Click here to Skip to main content
16,015,756 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
hello every one do you know how i can enable or disable tab pages in tab control.
for example when i click on the button tabpage1 is disable and click on other button enable it.
thank you.
Posted
Comments
Maarten Kools 3-Sep-13 11:09am    
What have you tried so far?
Edalat_2011 4-Sep-13 2:11am    
hi,i was create a C# windowsformsapplication and when i add a tab control on my project,
i want add a button and write a code to enable or disable tab pages in tab control object.

hello every one i found a solution for my problem
fist:
add a tab control,and a button on my project and the add this two methods to my project:
C#
public static void EnableTab(TabPage page, bool enable)
{
    EnableControls(page.Controls, enable);
}
private static void EnableControls(Control.ControlCollection ctls, bool enable)
{
    foreach (Control ctl in ctls)
    {
        ctl.Enabled = enable;
        EnableControls(ctl.Controls, enable);
    }
}

and then double click on the button and add this line to disable tab page :
C#
private void button1_Click(object sender, EventArgs e)
        {
            EnableTab(tabControl1.TabPages[tabControl1.SelectedIndex = 0], false);
        }


and for enable it i add an other button and add this line to enable tab page:

C#
private void button1_Click(object sender, EventArgs e)
        {
            EnableTab(tabControl1.TabPages[tabControl1.SelectedIndex = 0], true);
        }

resource:
Barnamenevis.org
 
Share this answer
 
hi,
link regarding Tab panels

http://www.asp.net/ajaxlibrary/tabs-control.ashx[^]

you can set the enabled property true or false

C#
protected void btn1_Click(object sender, EventArgs e)

{

tab1.Enabled=False
}




this may help you

Happy coding
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900