Tab page order with forms inheritance issue...

T

Tyler

I have a BaseForm with a tab control that has two tab pages on it.
When I create a DerivedForm based on the BaseForm I am able to add
pages to the form in the DerivedForm. I am also able to reorder all of
the pages on the tab control in design mode, however, as soon as I
compile to run, the reordering is lost. I have also tried
programmatically using SetChildIndex to reorder the tab pages in the
container, with the same effect. Does anyone know how to do this?

Here are the classes:

public class BaseForm : System.Windows.Forms.Form
{
protected System.Windows.Forms.TabControl tabControl1;
protected System.Windows.Forms.TabPage tabPage1;
protected System.Windows.Forms.TabPage tabPage2;

public BaseForm()
{
InitializeComponent();
}

private void InitializeComponent()
{
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.tabControl1.SuspendLayout();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(192, 74);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "tabPage1";
//
// tabPage2
//
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Size = new System.Drawing.Size(192, 74);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "tabPage2";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(336, 182);
this.Controls.Add(this.tabControl1);
this.Name = "Form1";
this.Text = "Form1";
this.tabControl1.ResumeLayout(false);
this.ResumeLayout(false);
}
}

public class DerivedForm : FormsInheritenceIssue.BaseForm
{
private System.Windows.Forms.TabPage tabPage3;

[STAThread]
static void Main()
{
Application.Run(new DerivedForm());
}

public DerivedForm()
{
InitializeComponent();
}

private void InitializeComponent()
{
this.tabPage3 = new System.Windows.Forms.TabPage();
this.tabControl1.SuspendLayout();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage3);
this.tabControl1.Name = "tabControl1";
this.tabControl1.Controls.SetChildIndex(this.tabPage2, 0);
this.tabControl1.Controls.SetChildIndex(this.tabPage1, 0);
this.tabControl1.Controls.SetChildIndex(this.tabPage3, 0);
//
// tabPage1
//
this.tabPage1.Name = "tabPage1";
//
// tabPage2
//
this.tabPage2.Name = "tabPage2";
//
// tabPage3
//
this.tabPage3.Location = new System.Drawing.Point(4, 22);
this.tabPage3.Name = "tabPage3";
this.tabPage3.Size = new System.Drawing.Size(192, 74);
this.tabPage3.TabIndex = 2;
this.tabPage3.Text = "tabPage3";
//
// DerivedForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(336, 182);
this.Name = "DerivedForm";
this.tabControl1.ResumeLayout(false);
this.ResumeLayout(false);
}
}
 
B

Bruce Wood

There is a bug in tab page serialization in the designer. It has
nothing to do with inheritance: tab pages are occasionally reordered
when your form is written. I've read that it has to do with the Z-order
of the tab pages, but I've never put that to the test.

What I do is in my form's Load event I .Clear() all of the tab pages
from the tab contorl and re-insert them programmatically in the order I
want them to appear. It's a sledgehammer, yes, but it works.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top