Windows Forms event “On Select Tab”?

后端 未结 5 1770
执念已碎
执念已碎 2021-01-01 12:08

I\'m building a Windows Forms application in C#. How do I trigger code when a certain tab on a tab menu is selected?

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-01 12:41

    For selecting a specific tab, can it only be identified by 0, 1, 2, and not the tab name?

    You can do this by adding the event listener to the actual tab rather than to the tab control.

    If you had a tab called tabHistory, you could add the following line in the designer.

    this.tabHistory.Enter += new System.EventHandler(this.tabHistory_Enter);
    

    Then just add your method to catch the event.

    private void tabHistory_Enter(object sender, EventArgs e)
    {
        MessageBox.Show("Hey! Ive got focus");
    }
    

提交回复
热议问题