Create TabPages at runtime (with controls)


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
 
Ad

Advertisements

A

Armin Zingler

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
 

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