Click here to Skip to main content
14,238,485 members

Determining which TabPage was clicked

Rate this:
5.00 (1 vote)
Please Sign up or sign in to vote.
5.00 (1 vote)
3 Jan 2012CPOL
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);
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jacek Gajek
Software Developer
Poland Poland
My name is Jacek Gajek. I have graduated in computer science with a master's degree from Polibuda in Wrocław. I like C# and Monthy Python's sense of humour.

Comments and Discussions

 
GeneralRe: Well, I just had a look and see the problem. I haven't thoug... Pin
PIEBALDconsult4-Jan-12 15:06
protectorPIEBALDconsult4-Jan-12 15:06 
GeneralWhat's the point of having a binary search version? Wouldn'... Pin
Fringe Coder9-Jan-12 15:32
memberFringe Coder9-Jan-12 15:32 
GeneralYeah, but that's the brain-dead version (no reflection on yo... Pin
PIEBALDconsult3-Jan-12 2:55
protectorPIEBALDconsult3-Jan-12 2:55 
GeneralRe: I have posted it for these who are actually brain-dead, as t... Pin
Jacek Gajek3-Jan-12 9:54
memberJacek Gajek3-Jan-12 9:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Alternative
Tip/Trick
Posted 3 Jan 2012

Tagged as

Stats

11K views
2 bookmarked