Click here to Skip to main content
15,789,840 members
Articles / Desktop Programming / Windows Forms

Determining which TabPage was clicked

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
3 Jan 2012CPOL 13.4K   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.
private static int
    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;

    return (result);


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 16:06
professionalPIEBALDconsult4-Jan-12 16:06 
GeneralWhat's the point of having a binary search version? Wouldn'... Pin
Fringe Coder9-Jan-12 16:32
Fringe Coder9-Jan-12 16:32 
GeneralYeah, but that's the brain-dead version (no reflection on yo... Pin
PIEBALDconsult3-Jan-12 3:55
professionalPIEBALDconsult3-Jan-12 3:55 
GeneralRe: I have posted it for these who are actually brain-dead, as t... Pin
Lutosław3-Jan-12 10:54
Lutosław3-Jan-12 10: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.