Option Explicit
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
Private Const LB_ITEMFROMPOINT = &H1A9
Private Sub Form_Load()
Dim i As Integer
For i = 0 To 5
List1.AddItem "ListItem字符串超长超长超长超长超长咯 " & i
Next
End Sub
Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lParam As Long
Dim lResult As Long
lParam = (CInt(Y / Screen.TwipsPerPixelY) * 2 ^ 16) + CInt(X / Screen.TwipsPerPixelX)
lResult = SendMessage(List1.hwnd, LB_ITEMFROMPOINT, 0, ByVal lParam)
If lResult < 0 Or lResult > 32767 Then
List1.ToolTipText = ""
Exit Sub
End If
Dim nIndex As Integer
nIndex = CInt(lResult)
List1.ToolTipText = List1.List(nIndex)
End Sub
List控件鼠标移动提示功能实现
博客展示了一段代码,实现了List控件在鼠标移动时显示对应项提示信息的功能。通过声明SendMessage函数,在Form_Load事件中添加列表项,在List1_MouseMove事件中根据鼠标位置获取列表项索引,并将对应项内容设为提示文本。
1577

被折叠的 条评论
为什么被折叠?



