这样的事情:
private void secondTabPageInTabControl_Click(object sender, System.EventArgs e)
{
this.myTreeView.Enable = false;
} //then I chose other tabpages and it becomes enable
答案 0 :(得分:1)
改为使用TabControl的SelectedIndexChanged事件。它会告诉您何时选择了新选项卡。使用与此类似的代码:
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) {
this.myTreeView.Enable = tabControl1.SelectedTab != tabPage2;
}
或者通过索引,不太可读:
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) {
this.myTreeView.Enable = tabControl1.SelectedIndex != 1;
}
答案 1 :(得分:0)
另一种解决方案,但请注意,如果您使用太多的标签页,这可能会变得臃肿:p>
private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
{
UpdateUI(e.TabPageIndex);
}
public void UpdateUI(int index)
{
switch (index)
{
case 0:
treeView1.Enabled = true;
break;
case 1:
treeView1.Enabled = false;
break;
case 2:
treeView1.Enabled = false;
break;
default:
treeView1.Enabled = false;
break;
}
}