我有这个代码来禁用标签页:
private void tabControl_Selecting(object sender, TabControlCancelEventArgs e)
{
if (e.TabPage == tabPage)
{
e.Cancel = true;
}
}
我希望在点击按钮时启用它。有办法吗?
答案 0 :(得分: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;
}
}