Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Determining which TabPage was clicked

0.00/5 (No votes)
3 Jan 2012 1  
This method, although it doesn't use binary search, handles Multiline tab pages too.private static intGetTabIndexAt( System.Windows.Forms.TabControl tabControl, System.Drawing.Point point){ int result = -1; if (tabControl != null) { for (int i = 0;...
This method, although it doesn't use binary search, handles Multiline tab pages too.
C#
private static int
GetTabIndexAt
(
    System.Windows.Forms.TabControl tabControl
,
    System.Drawing.Point point
)
{
    int result = -1;

    if (tabControl != null)
    {
        for (int i = 0; i < tabControl.TabPages.Count; i++)
        {
            System.Drawing.Rectangle rect = tabControl.GetTabRect(i);
            if (rect.Contains(point))
            {
                result = i;
                break;
            }

        }
    }
    return (result);
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here