如何在LISTBOX中移动鼠标就可以起到CLICK的作用

百度网友a8566ae2940
2013-10-11 · TA获得超过3866个赞
知道小有建树答主
回答量:948
采纳率:100%
帮助的人:702万
展开全部
下面用两种方法分别一试:方法1�0�2 Sendmessage 向LISTBOX发送消息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 Byte For i = 1 To 20 List1.AddItem String(i, Chr(i + 64))NextEnd SubPrivate Sub List1_Click() '随时看到效果 Me.Caption = "The listitem you select is """ & List1.Text & """" End SubPrivate Sub List1_Mousemove(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim lX As Long, lY As Long, lIndex As Long �0�2�0�2�0�2�0�2�0�2�0�2�0�2 lX = CLng(X / Screen.TwipsPerPixelX) �0�2�0�2�0�2�0�2�0�2�0�2�0�2 lY = CLng(Y / Screen.TwipsPerPixelY) �0�2�0�2�0�2�0�2�0�2�0�2�0�2 lIndex = SendMessage(List1.hwnd, LB_ITEMFROMPOINT, 0, ByVal ((lY * &H10000) + lX)) If lIndex >= 0 And lIndex <= List1.ListCount Then List1.Selected(lIndex) = True End Sub方法2�0�2 模拟鼠标左键单击Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long) Private Const MOUSEEVENTF_LEFTDOWN = &H2 Private Const MOUSEEVENTF_LEFTUP = &H4 Private Const MOUSEEVENTF_ABSOLUTE = &H8000Private Sub Form_Load() Dim i As Byte For i = 1 To 20 List1.AddItem String(i, Chr(i + 64))NextEnd SubPrivate Sub List1_Click() '随时看到效果 Me.Caption = "The listitem you select is """ & List1.Text & """" End SubPrivate Sub List1_Mousemove(Button As Integer, Shift As Integer, X As Single, Y As Single)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式