【问题标题】:Disable tabpage and enable when button is click in c#在c#中单击按钮时禁用标签页并启用
【发布时间】:2017-03-17 13:04:30
【问题描述】:
我有这个代码来禁用标签页:
private void tabControl_Selecting(object sender, TabControlCancelEventArgs e)
{
if (e.TabPage == tabPage)
{
e.Cancel = true;
}
}
我想在单击按钮时启用它。有办法吗?
【问题讨论】:
标签:
c#
tabcontrol
tabpage
【解决方案1】:
在表单中声明 bool 属性,如下所示:
public Form1
{
bool TabSelectingAllowed {get;set;}
当用户点击按钮时,改变值
private void button1_Click(object sender, EventArgs e)
{
TabSelectingAllowed = true;
}
在您现有的代码中添加对该属性值的额外检查
private void tabControl_Selecting(object sender, TabControlCancelEventArgs e)
{
if (e.TabPage == tabPage)
{
if (!TabSelectingAllowed)
e.Cancel = true;
}
}