Enable ot Disable a Tab in Tab Control using VB.Net

M

Mick Doherty

The simple answer is that you cannot disable a tab. You can disable a
tabpage but that will only stop you from interacting with the page, it will
not stop you from selecting it.

In VS2005 you can intercept and prevent the selection by setting e.Cancel to
true in the BeforeSelect method of the tabcontrol.

In VS2002/2003 the tabcontrol does not have this method and so you need to
add it as per the example on my site:
http://dotnetrix.co.uk/tabcontrols.html --> Add SelectedIndexChanging Event.

This will still require you to ownerdraw the tabcontrol in order to get the
disabled appearance.

The recommended method is to remove tabpages rather than disable them. You
will find methods to remove and re-insert tabpages on my site.
http://dotnetrix.co.uk/tabcontrols.html --> Hide and Show Tabpages in a
Tabcontrol.

If you really want to disable tabs, and have them appear disabled, but do
not want to write lots of code to do it then you need a third party control.

There is one on my site, which you are free to use in any way you wish.
http://www.dotnetrix.co.uk/controls.html --> TabControlEx.
 
Joined
Apr 19, 2013
Messages
1
Reaction score
0
I have a simple suggestion if you are using VS2010 instead of enabling and disabling a tab
Add the tab pages in design time and if don't need a tab then remove it on runtime like below
TabControl1.Controls.Remove(TabPage2)
where TabControl1 is the tabbed control and TabPage1 is the second tab

You could readd anytime by using add method of the controls.
TabControl1.Controls.Add(TabPage2)
In order to invalidate the controls, please include the following line
TabPage3.Refresh()
 
Last edited:

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

Similar Threads


Top