Click here to Skip to main content
15,860,972 members
Articles / Desktop Programming / Windows Forms
Alternative
Tip/Trick

Determining which TabPage was clicked

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
3 Jan 2012CPOL 13.7K   3   4
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Poland Poland
My name is Jacek. Currently, I am a Java/kotlin developer. 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
mvePIEBALDconsult4-Jan-12 15:06 
GeneralWhat's the point of having a binary search version? Wouldn'... Pin
Fringe Coder9-Jan-12 15:32
Fringe Coder9-Jan-12 15:32 
GeneralYeah, but that's the brain-dead version (no reflection on yo... Pin
PIEBALDconsult3-Jan-12 2:55
mvePIEBALDconsult3-Jan-12 2:55 
GeneralRe: I have posted it for these who are actually brain-dead, as t... Pin
Lutosław3-Jan-12 9:54
Lutosław3-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.