tags:

views:

866

answers:

2
TabPage newpage = new TabPage();
Tabs.TabPages.Add(newpage);
newpage.Controls.Add(this.tableLayoutPanel41);
newpage.Location = new System.Drawing.Point(4, 26);
newpage.Name = "AddMaintAgreement" + offset;
newpage.Size = new System.Drawing.Size(736, 523);
newpage.TabIndex = 10;
newpage.Text = "Add Maintenance Agreement";
newpage.UseVisualStyleBackColor = true;
offset++;

Basically thats what i have at the moment, I added the offset in there because i thought it might affect my problem.

Basically, this code here works okay for adding one "addmaintagreement" tab. After that only the latest tab has any controls on it!

Basically I'm stumped. Any help would be appreciated. Thanks.

A: 

Controls can only be parented to one control, but it looks like you are trying to parent your tableLayoutPanel41 in every TabPage instance. You need to create new copies of the controls for each instance of the tab. There are various ways to fix this.

  1. Programmatically create your tab page and its contents multiple times.
  2. Have the contents of your TabPage implemented as a user control that you dock fill on a tab page. Then recreate one of those for each page duplicate your require.
  3. Create a class derived from TabPage that implements your tab page and create new instances of that for each use.
Jeff Yates
+1  A: 

Derive from TabPage and add the controls you want in that derived class. Then use your derived class instead of TabPage.

Daniel Brückner