TabControl question.

G

Gav

I am writing an application where I will have a TabControl and 3 styles of
Tabs to go in it, each containing different controls. The tabs will be added
to the tabcontrol when items are clicked on in a TreeView. So the the
application starts by displaying no tabs and adds them in as required. There
could be any number of each tab (0 upwards).

What is the best way of me doing this? Should I create 3 custom controls
that extend TabPage? I've only been doing this for a couple of days so any
advice would be great.

thanks

Gav
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

Gav said:
I am writing an application where I will have a TabControl and 3 styles of
Tabs to go in it, each containing different controls. The tabs will be
added to the tabcontrol when items are clicked on in a TreeView. So the the
application starts by displaying no tabs and adds them in as required.
There could be any number of each tab (0 upwards).

What is the best way of me doing this? Should I create 3 custom controls
that extend TabPage? I've only been doing this for a couple of days so any
advice would be great.

When you are designint it just create your TabPages inside the tabcontrol,
when you are done you remove the part of the code when those pages are added
to the tabcontrol. Finally you can add/remove then using code:

tabControl.TabPages.Remove( tabPage1);
tabControl.TabPages.Add( tabPage2);


tabPageXXX will be created by the designer and will be member of the class.

If you want to do this dynamically you can do a similar approach but just
creating the pages as you need, In this case you just cut the code generated
by the designer.
 
N

nano2k

I am writing an application where I will have a TabControl and 3 styles of
Tabs to go in it, each containing different controls. The tabs will be added
to the tabcontrol when items are clicked on in a TreeView. So the the
application starts by displaying no tabs and adds them in as required. There
could be any number of each tab (0 upwards).

What is the best way of me doing this? Should I create 3 custom controls
that extend TabPage? I've only been doing this for a couple of days so any
advice would be great.

thanks

Gav

I'm not sure I fully understand what you want to do, but I can give
you an idea, and you'll decide if it fits for you.
I would create in designed a single TabControl containing ALL
possibile TabPages.
In form's constructor, right after calling InitializeComponent(), I
would initialize 3 arrays of TabPages. You must declare the array as
members of your form's class. Each array containg the combination of
TabPages that should be displayed when items are clicked in TreeView
control. I would set the Tag property of each TreeNode to the
corresponding array. This will help you later.

After initializing the arrays, you may clear all TabPages, so
initially, you have an empty TabControl.
When a TreeNode is selected, you just need to:
1. clear the TabPages in TabControl.
2. get the list of TabPages using TreeNode's Tag property and add the
pages to the TreeControl.

I didn't try this, but I don't see any reason it shouldn't work...
Hope it helps.
 

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