Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1290
How to dynamically assign event handler to tab page's tab header
posted

This is how I'm adding tab pages into my controls:

 childTabControl.Tabs.Add(tabName, tabName);

I would like to raise a click event to say.. display the tab name in a message box once I click the tab, how do I do that?

  • 37774
    Verified Answer
    posted

    You could get this quickly through the GetContext method call of the UIElement of the control:

    private void ultraTabControl1_MouseClick(object sender, MouseEventArgs e)
    {
        if (e.Button != MouseButtons.Left)
            return;

        UltraTab tab = this.ultraTabControl1.UIElement.LastElementEntered.GetContext(typeof(UltraTab)) as UltraTab;
        if (tab != null)
            MessageBox.Show(tab.Text);
    }

    -Matt