tooltip for tabcontrol headers?

  • Thread starter Thread starter Lisa
  • Start date Start date
L

Lisa

I'm trying to display tooltips when the mouse hovers over the header of
individual tab pages in a tab control, but the tt only displays when the
mouse is over the body of the tab page. Is this by design? What am I doing
wrong?
 
The Tabpage headers are drawn on the tabcontrol and are not part of the
Tabpage, so you need to set the Tooltip of the TabControl and not the
Tabpage.

The following code sample will do as you require, but could do with some
tweaking:

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Private Sub TabControl1_MouseMove(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles TabControl1.MouseMove
Dim HoverTab As Integer = TestTab(New Point(e.X, e.Y))
If HoverTab >= 0 Then
ToolTip1.SetToolTip(TabControl1, TabControl1.TabPages(HoverTab).Text)
End If
End Sub

Private Function TestTab(ByVal pt As Point) As Integer
Dim returnIndex As Integer = -1
For Each t As TabPage In TabControl1.TabPages
If TabControl1.GetTabRect(t.TabIndex).Contains(pt.X, pt.Y) Then
returnIndex = t.TabIndex
End If
Next
Return returnIndex
End Function

Private Sub TabControl1_MouseLeave(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles TabControl1.MouseLeave
ToolTip1.SetToolTip(TabControl1, nothing)
End Sub

////////////////////////////////////////////////////////////////////////

Mick
 
Back
Top