Click here to Skip to main content
15,908,768 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have a pretty simple .net c# vs 2012 app. I'm learning to use the tabcontrol programatically. I've been looking for a few hours and cannot find what I am doing wrong. My simple code below does not show on my main form. Every sample and example that I have looked at does not more than this and yet this does not show. Obviously I am missing something.

Thanks for any help...


C#
private void Form1_Load(object sender, EventArgs e)
{
    TabPage newPage = new TabPage("New Page");
    TabControl tabControl = new System.Windows.Forms.TabControl();
    tabControl.TabPages.Add(newPage);

}
Posted

You add the newPage tab to the tabControl, but you never add the tabControl to your form. Try this...

C#
private void Form1_Load(object sender, EventArgs e)
{
    TabPage newPage = new TabPage("New Page");
    TabControl tabControl = new System.Windows.Forms.TabControl();
    tabControl.TabPages.Add(newPage);
    this.Controls.Add(tabControl);
}
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 2-Sep-13 22:01pm    
Good catch, but I fixed casing in the code and formatting. Voted 4.
—SA
idenizeni 2-Sep-13 22:48pm    
Thank you :)
Thank you...the demos I saw must have had that code added perhaps via the designer but in any event, that did work...thanks a lot...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900