ViewCodeTooltip



Option Explicit
' Declare the API function call.

'_________________________________________________________

Private Declare Function SendMessage _
Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
' Add API constant

Private Const LB_ITEMFROMPOINT = &H1A9
'Next, add some code to the form load event to fill the

'ListBox with data:

'_________________________________________________________

Private Sub Form_Load()
'

' load some items in the list box

With List1
.AddItem "Michael Clifford Amundsen"
.AddItem "Walter P.K. Smithworthy, III"
.AddItem "Alicia May Sue McPherson-Pennington"
End With
'

End Sub

'_________________________________________________________

'Finally, in the MouseMove event of the ListBox, put the

'following code:

Private Sub List1_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
'

' present related tip message

'

Dim lXPoint As Long
Dim lYPoint As Long
Dim lIndex As Long
'

If Button = 0 Then ' if no button was pressed
lXPoint = CLng(X / Screen.TwipsPerPixelX)
lYPoint = CLng(Y / Screen.TwipsPerPixelY)
'

With List1
' get selected item from list

lIndex = SendMessage(.hwnd, LB_ITEMFROMPOINT, 0, _
ByVal ((lYPoint * 65536) + lXPoint))
' show tip or clear last one

If (lIndex >= 0) And (lIndex <= .ListCount) Then
.ToolTipText = .List(lIndex)
Else
.ToolTipText = ""
End If
End With '(List1)
End If '(button=0)
'

End Sub


(viewcodetooltip.html)- by Paolo Puglisi - Modifica del 25/3/2019