emiraslan emiraslan - 1 year ago 165
C# Question

Controls.Add(tabPage) vs. TabPages.Add(tabPage)

To create a new tab in winform application I found this in msdn:

string title = "TabPage " + (tabControl1.TabCount + 1).ToString();
TabPage tabPage1 = new TabPage(title);

But when I add a tab manually from Form1.cs[Design] Visual Studio automatically creates this in Form1.Designer.cs for a new tab:

private System.Windows.Forms.TabPage tabPage1;
this.tabPage1 = new System.Windows.Forms.TabPage();

So, what is the main difference between

Answer Source

There is no difference. Here is the source code for TabPageCollection.Add method:

public void Add(TabPage value) {
    if (value == null) {
        throw new ArgumentNullException("value");

In above code, the owner is the TabControl which owns the TabPageCollection.

The benefit of using TabPageCollection is in 5 different overloads which it provides for adding tab pages to the TabControl.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download