TabControl bug?

  • Thread starter Thread starter Leif Eirik Olsen
  • Start date Start date
L

Leif Eirik Olsen

Hi,

TabControl with 10 tabpages: In designtime reorder tabpages, press Ok in
property editor, save solution and exit VS. Reopen project and tabpages
appear in a different order!

Is this a known bug and/or is there any know workaroud to avoid this?

Thanks,
Leo
 
Modifying them in InitializeComponent is a bad idea. If you modify (or
maybe even just view) the designer, it will re-write that code. You must
re-order the tabs manualy after InitializeComponent

-Chris
 
Modifying them in InitializeComponent is a bad idea. If you modify (or
maybe even just view) the designer, it will re-write that code. You must
re-order the tabs manualy after InitializeComponent

Yes I guess you're right, but I could not resist trying :)

What I did was:
1. Save my project
2. Open and alter the creation order of the tabs in the InitializeComponent
3. Save and exit all
4. Open project again.

Now it seems (just a guess mabe) that if I do not touch the designtime popup
component editor the taborder is fine :)

Thanks,
Leo
 
Now it seems (just a guess mabe) that if I do not touch the designtime
popup
component editor the taborder is fine :)
Yes that is correct.

Like I suggested, if you do it in the form load event then you can use the
form designer too.

Cheers
Daniel
 
Daniel Moth said:
Yes that is correct.

Like I suggested, if you do it in the form load event then you can use the
form designer too.

Well....

aTabControl.Controls.SetChildIndex(this.aTabPage, 1); Does not seem to have
any affect in my application, so my 'only' option was to re-order the
creation-order of the tabs under the InitializeComponent.

regards,
Leo
 
Yes I realise SetChildIndex did not work for you. What I suggested was that
you add the tabpages in the load event (or after InitializeComponent). That
way you get the designer back.

Cheers
Daniel
 
Daniel Moth said:
Yes I realise SetChildIndex did not work for you. What I suggested was that
you add the tabpages in the load event (or after InitializeComponent). That
way you get the designer back.

Sorry, not sure I understand what your suggesting here.

Ex.
public frmMain()
{
InitializeComponent();

TabPage aPage1 = new System.Windows.Forms.TabPage();
TabPage aPage2 = new System.Windows.Forms.TabPage();
aTabControl.Controls.Add(aPage1); //aTabControl already created
aTabControl.Controls.Add(aPage2);
}

Is this what you are suggesting? And, if so, do you say that aPage1 and
aPage2 now should be visable and available designtime?

reagrds,
Leo
 
You can do all the tabpage creation/addition like your example and you will
have designer support for all elements of your form *except* the tabcontrol.
Alternatively, instead of your code:

aTabControl.TabPages.Clear();
aTabControl.TabPages.Add(this.MyTabPageAlreadyDeclaredAndPopulated);
// repeat addition of tabpages
this.MyTabPageAlreadyDeclaredAndPopulated.Text = "must reassign the name"
//repeat foreach tabpage added

You now have designer support and they will appear in the right order (at
the runtime expense of clearing/readding the tabpages).

Cheers
Daniel
 
Daniel Moth said:
You can do all the tabpage creation/addition like your example and you will
have designer support for all elements of your form *except* the tabcontrol.
Alternatively, instead of your code:

Thanks again Daniel,

I'll have a go right away.

regards,
Leo
 
Back
Top