Tuesday, May 5, 2009

How to disable a TabPage in the TabControl


Scenario
The component TabControl in the Visual Studio IDE does not allow people to
disable a certain TabPage within the TabControl. I have Googled for a long time
and there is not any real solution regarding this issue. However, some people put a
customized TabControl which allows you to disable the TabPage. I believe not
everyone wants to download and try the third party software or plug-in.

Method
I'm going to talk about a 'solution' which is more like a trick to solve this problem.
For example, let's create a TabControl and it has 2 TabPages. Now before
dragging any other objects from the tool list, drag a Panel object and drop into
each one of those TabPages. Set those three Panels' Dock property to Fill so
that the panel will be maximized within its TabPage. Now you will probably guess
what I'm trying to tell you. Yes, you put all other objects on top of the panel.
Then you just disable the panel if you want to disable a TabPage. Because the
Panel is the Parent of the other components, the panel and its children will be
disabled if we try to disable the panel itself.

Details
Let's have a look at how this works.

First, create a TabControl and drop a Panel onto one of the tab pages.


Now, set the Dock to Fill for the panel


Add some components to the tabPage1. Actually they are on top of the
panel1. Run the sample application without checking the 'Enable Panel1'
checkbox.


The code implementation for the checkbox. Just for testing.


The effect shows the tabPage1 is 'disabled' once the checkbox is unchecked.

Summary
This solution might not be perfect to everyone, but I believe it will help some
people like me to solve a problem by using a simple solution. Remember the KISS
principle? This is all about it!

comments

0 Responses to "How to disable a TabPage in the TabControl"

Post a Comment

BlogUpp!

 

Copyright 2009 All Rights Reserved Revolution Two Lifestyle theme by Brian Gardner | Blogger template converted & enhanced by eBlog Templates