0

像这样的东西:

private void secondTabPageInTabControl_Click(object sender, System.EventArgs e)
        {
           this.myTreeView.Enable = false; 
        } //then I chose other tabpages and it becomes enable
4

2 回答 2

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;
    }
于 2012-09-05T14:20:07.167 回答
0

另一种解决方案,但请注意,如果您使用太多标签页,这可能会变得臃肿:

    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;
        }
    }
于 2012-09-05T14:27:32.840 回答