The tabcontrol for my windows form shows horizontal scroll for the tab pag header if too many tabs are opened with arrows .
But the below condition shows the wrong tab page when the horizontal scroll is used and trying to mouse over the overflowing tabs.
Private Sub OnTabMouseEnter(sender As Object, e As MouseEventArgs) Handles TabControl1.MouseMove
Dim tp As TabPage
Dim r As Rectangle
' Start clean
OnTabMouseLeave(sender, e)
Try
' find the tab by iteration
For i As Integer = 0 To (TabControl1.TabPages.Count - 1)
r = TabControl1.GetTabRect(i)
If r.Contains(TabControl1.PointToClient(Cursor.Position)) Then
'enters this loop for wrong tab while mouse over the overflowing tab headers
Exit For
End If
Next
Catch ex As Exception
gLogClient.Exception(ex, Me, "OnTabMouseEnter()")
End Try
End Sub
it is a simple tab control with pages dynamically added...So you can create a tab control with atleast 10 pages and attach the below event without the picclosebuttoncode .
instead of picclosebutton show a message box saying which tabpage index is shown.
You will see that the wrong tab page index is shown when mosuing over the overflowing tab headers.
Private Sub OnTabMouseEnter(sender As Object, e As MouseEventArgs) Handles TabControl1.MouseMove
Dim tp As TabPage
Dim r As Rectangle
' Start clean
OnTabMouseLeave(sender, e)
Try
' find the tab by iteration
For i As Integer = 0 To (TabControl1.TabPages.Count - 1)
r = TabControl1.GetTabRect(i)
If r.Contains(TabControl1.PointToClient(Cursor.Position)) Then
tp = TabControl1.TabPages(i)
' Left position
picCloseButton.Top = TabControl1.Top + 4 + (TabControl1.ItemSize.Height - picCloseButton.Height) / 2
picCloseButton.Left = TabControl1.Left + 4 + TabControl1.ItemSize.Width * (i + 1) - 20
picCloseButton.Height = 16
picCloseButton.Width = 16
picCloseButton.Visible = True
picCloseButton.BringToFront()
picCloseButton.Tag = tp
Exit For
End If
Next
Catch ex As Exception
gLogClient.Exception(ex, Me, "OnTabMouseEnter()")
End Try
End Sub
Private Sub OnTabMouseLeave(sender As Object, e As EventArgs) Handles TabControl1.MouseLeave
Try
' Hide the close button but not if the mouse is above the close button itself
Dim p As Point = picCloseButton.PointToClient(Cursor.Position)
If p.X > picCloseButton.Width Or p.Y > picCloseButton.Height Then
picCloseButton.Tag = Nothing
picCloseButton.Hide()
End If
Catch ex As Exception
gLogClient.Exception(ex, Me, "OnTabMouseLeave()")
End Try
End Sub