You need to handle the
MouseDown
event for the
TabControl
, and check to see which tab contained the the mouse cursor. This is done by checking the bounding rectangle of each tab (the corresponding tab, not the
TabPage
itself). Here's some modified code that should help. When you press a L or R mouse button over a tab, a
MsgBox
will give you the proper
TabPage
.
Public Class Form1
Friend WithEvents MaxTab As TabControl
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
MaxTab = New TabControl
MaxTab.Name = "tabd"
MaxTab.Top = 1
MaxTab.Size = New System.Drawing.Size(Me.Width - 15, Me.Height - 80)
MaxTab.TabPages.Add("dTAB1")
MaxTab.TabPages.Add("dTAB2")
AddHandler MaxTab.MouseDown, AddressOf tabs_MouseDown
Me.Controls.Add(MaxTab)
MaxTab = New TabControl
MaxTab.Name = "tabr"
MaxTab.Top = 1
MaxTab.Size = New System.Drawing.Size(Me.Width - 15, Me.Height - 80)
MaxTab.TabPages.Add("rTAB1")
MaxTab.TabPages.Add("rTAB2")
Me.Controls.Add(MaxTab)
Me.Controls("tabr").Visible = False
Me.MaxTab.Refresh()
End Sub
Private Sub tabs_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MaxTab.MouseDown
Dim r As Rectangle
Dim ll As Integer
For ll = 0 To MaxTab.TabPages.Count - 1
r = MaxTab.GetTabRect(ll)
If e.X >= r.Left And e.X <= r.Right And e.Y >= r.Top And e.Y <= r.Bottom Then
MsgBox(MaxTab.TabPages(ll).Text)
Exit For
End If
Next
End Sub
End Class