Create TabPages at runtime (with controls)

  • Thread starter Thread starter Luc
  • Start date Start date
L

Luc

Hi,

I have a TabControl and, at runtime, I need to add some tabpages. The
problem is that each tabpage is similar to the others and contains several
controls.

If I do TabControl.TabPages.Add(MyTabPage), a new BLANK tabpage is added.
How can I add in few statements a new tabpage as well as its controls
(textboxes, labels, etc.)? The first tabpage (that I create at design time)
is the "template" to be used for the other tabpages. Is there a way at
runtime to duplicate the first tabpage and create new tabpages based on this
one (including controls)? Also: how can I reference (at runtime) the newly
created tabpages and their controls?

Thanks,

Luc
 
Luc said:
I have a TabControl and, at runtime, I need to add some tabpages.
The problem is that each tabpage is similar to the others and
contains several controls.

If I do TabControl.TabPages.Add(MyTabPage), a new BLANK tabpage is
added. How can I add in few statements a new tabpage as well as its
controls (textboxes, labels, etc.)? The first tabpage (that I create
at design time) is the "template" to be used for the other tabpages.
Is there a way at runtime to duplicate the first tabpage and create
new tabpages based on this one (including controls)? Also: how can I
reference (at runtime) the newly created tabpages and their
controls?

You could create a Usercontrol and put it on the first TabPage. Then, at
runtime, create new instances of the Tabpage and the Usercontrol.

Or, derive your own class from the Tabpage class, but you won't be able to
use a designer to design it.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Back
Top