简体   繁体   English

禁用选项卡并在c#中单击按钮时启用

[英]Disable tabpage and enable when button is click in c#

I have the this code to disable tab page: 我有此代码来禁用标签页:

private void tabControl_Selecting(object sender, TabControlCancelEventArgs e)
    {
        if (e.TabPage == tabPage)
        {
            e.Cancel = true;
        }
    }

and i want to enable it when a button is click. 我想在单击按钮时启用它。 Is there a way to do it? 有办法吗?

declare bool property in your form, something like this: 以您的形式声明bool属性,如下所示:

public Form1
{
   bool TabSelectingAllowed {get;set;}

when user clicks on button, change value 当用户单击按钮时,更改值

private void button1_Click(object sender, EventArgs e)
{
    TabSelectingAllowed = true;
}

in you existing code add additional checking for value of that property 在现有代码中,添加对该属性值的附加检查

private void tabControl_Selecting(object sender, TabControlCancelEventArgs e)
{
    if (e.TabPage == tabPage)
    {
       if (!TabSelectingAllowed)
           e.Cancel = true;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM