Click to See Complete Forum and Search --> : Dynamic TabControls and Tabpages


kewlbuddy
September 26th, 2006, 09:06 AM
Hello Friends,

My Form opens with two tabcontrols(in two rows) and each tabcontrol has 2 tabpages.
Now in the menuof the Form..I have to set an option where I can give number of tabcontrols and tabpages to be displayed..If i give 4 tabcontrols and each tabcontrol must have 4 tabpages..then Form must display those..
How to do this dynamically?Can anyone gimme hints/suggestions how to do this?

Thanx in advance

jhammer
September 26th, 2006, 09:31 AM
To add a TabControl to the form you should write:

Dim tc As New TabControl
Me.Controls.Add(tc)

If you want to show the tabcontrols one below the other, then you should play with the Dock property.

To add a TabPage to the TabControl write:

Dim tp As New TabPage
tp.Text = "whatever"
tc.TabPages.Add(tp)


I hope this makes sense to you.

kewlbuddy
September 26th, 2006, 09:35 AM
Thanx for ur reply..I know how to add tabcontrol and then add tabpage to it..
But what I want to know is whether can we add them dynamically at runtime?

talksandy
September 26th, 2006, 09:47 AM
I dont see why you cant.

You better try it first :)

It will work.

jhammer
September 26th, 2006, 10:09 AM
Sorry about the VB code (forgot this is the c# forum ;) )

Well, of course you can add controls dynamically (we are talking about windows forms, right?). Just write the code in any method of your form and see for your self.

BTW: Actually, when you drag controls to the form at design time, the IDE generates code that places the controls on the form at run-time - whe the application starts up (so in fact there is no such thing as statically placing controls - everything is at runtime).

kewlbuddy
September 27th, 2006, 10:19 AM
Sorry about the VB code (forgot this is the c# forum ;) )

Well, of course you can add controls dynamically (we are talking about windows forms, right?). Just write the code in any method of your form and see for your self.

BTW: Actually, when you drag controls to the form at design time, the IDE generates code that places the controls on the form at run-time - whe the application starts up (so in fact there is no such thing as statically placing controls - everything is at runtime).
Sorry friend, u misunderstood my question...What I mean is in design time I draw 2 tabcontrols,code is generated automatically and they r displayed at runtime....but in runtime,can I add a new tabcontrol which is not designed/declared/coded in Form?