65.9K
CodeProject is changing. Read more.
Home

Determining which TabPage was clicked

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Jan 3, 2012

CPOL
viewsIcon

14529

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.
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);
}