Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2005

Tip: Looking for answers? Try searching our database.

Tab page order with forms inheritance issue...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tyler - 19 Jan 2005 16:48 GMT
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);
        }
    }
Bruce Wood - 19 Jan 2005 21:33 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.