Check if a specific tab page is selected (active)

后端 未结 6 1664
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-14 05:43

I am making an event to check if specific tab page in a tab control is active.

The point is, it will trigger an event if that tab page in a tab control is the curren

6条回答
  •  孤城傲影
    2020-12-14 06:12

    I think that using the event tabPage1.Enter is more convenient.

    tabPage1.Enter += new System.EventHandler(tabPage1_Enter);
    
    private void tabPage1_Enter(object sender, EventArgs e)
    {
        MessageBox.Show("you entered tabPage1");
    }
    

    This is better than having nested if-else statement when you have different logic for different tabs. And more suitable in case new tabs may be added in the future.

    Note that this event fires if the form loads and tabPage1 is opened by default.

提交回复
热议问题