Right clicking a Tab

daysanew

New member
Joined
May 10, 2006
Messages
3
Programming Experience
Beginner
Hey everyone,

I am trying to figure out how I can tell what object has been right clicked. Let me explain the situation.

I have a tab control, an user can create several tabs (I've yet to program a limit into it), basically when a user clicks a button, a tab is created and a custom control is dropped on that tab. Each tab is named based on how many tabs are open. So basically I can't use an event to know when a certain tab is right clicked, so I need to figure out how I can capture what object was just clicked so I can use it to say close the tab.

Also does anyone know how you can change the color the tab control itself when all tabs are closed? Right now it is an ugly gray color.

Thanks for the help.
 
I use this utility function to hit-test a Point with each the tab rectangles (GetTabRect):
VB.NET:
Function getTabAt(ByVal tc As TabControl, ByVal pt As Point) As TabPage
    For i As Integer = 0 To tc.TabCount - 1
        If tc.GetTabRect(i).Contains(pt) Then
            Return tc.TabPages(i)
        End If
    Next
    Return Nothing
End Function
example usage:
VB.NET:
Private Sub TabControl1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles TabControl1.MouseClick
    If e.Button = Windows.Forms.MouseButtons.Right Then
        Dim tp As TabPage = getTabAt(sender, e.Location)

    End If
End Sub
 
Yes, but you have to use MouseDown event in that case.
 
Back
Top