dynamically adding tabpages to a tabcontrol
-
I want to add tabpages to a tab control at runtime. And I should be able to specify those tabpages' names at runtime as well.HOw can I achive this? samitha
The same way the designer does it - this isn't magic like Visual Basic (6 and below). Designer code is serialized to source code; taking a look at that would be a first step to understanding. The
TabControl
has a collection property -TabPages
- that you can add instances of aTabPage
to. If you read the .NET Framework SDK for both of these classes, setting a title and adding a page to a tab control should be obvious:TabPage page = new TabPage("My Caption");
tabControl1.TabPages.Add(page);Microsoft MVP, Visual C# My Articles
-
The same way the designer does it - this isn't magic like Visual Basic (6 and below). Designer code is serialized to source code; taking a look at that would be a first step to understanding. The
TabControl
has a collection property -TabPages
- that you can add instances of aTabPage
to. If you read the .NET Framework SDK for both of these classes, setting a title and adding a page to a tab control should be obvious:TabPage page = new TabPage("My Caption");
tabControl1.TabPages.Add(page);Microsoft MVP, Visual C# My Articles
as you have mentioned I have put my code as follows //this method is called from the main windows form public void AddNewTabPage() { if(tabReportPages==null) { this.InitializeComponent(); } System.Windows.Forms.TabPage tabPage1 = new System.Windows.Forms.TabPage("test"); // // tabPage1 // tabPage1.Location = new System.Drawing.Point(4, 22); tabPage1.Name = "tabPage1"; tabPage1.Size = new System.Drawing.Size(536, 310); tabPage1.TabIndex = 0; this.tabReportPages.TabPages.Add(tabPage1); //....continues for the othe tab pages tabPage1.Show(); tabPage1.BringToFront(); tabPage2.Show(); //..continues for the other tab pages } but any of the tab pages are not showing..why is that?(the tab control is added to a user control) samitha
-
I want to add tabpages to a tab control at runtime. And I should be able to specify those tabpages' names at runtime as well.HOw can I achive this? samitha
hi, i have a tab control with one tabpage and a button in my form. On button click i am executing this much code. TabPage Newtab=new TabPage("ha ha"); this.tabControl1.TabPages.Add(Newtab); Is the same you want ? ************************** S r e e j i t h N a i r **************************