Listbox控件没有提供这个属性值可以调用,这里我写了个完整的演示程序,供大家参考.
新建一个工程,在Form1窗体上加上一个ListBox和一个Label.在窗体代码中粘贴以下程序,然后运行即可.
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 = &H1A9Private Sub Form_Load()
Dim i As Integer
For i = 1 To 5
List1.AddItem Trim(Str(i))
Next
End SubPrivate Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim LstPOS As Long
Dim XX As Long
Dim YY As Long
XX = CLng(X / Screen.TwipsPerPixelX)
YY = CLng(Y / Screen.TwipsPerPixelY)
LstPOS = SendMessage(List1.hwnd, LB_ITEMFROMPOINT, 0, ByVal ((YY * 65536) + XX))
If LstPOS < List1.ListCount Then
Label1.Caption = "当前位置为: " & LstPOS
End If
End Sub
'-------------------------------------------
' 作者:唐细刚