如何用右键选定一个列表控件(listbox)中的一行?
如题,当我在列表控件中(listbox)的某一行上点击右键时,先选定这一行(效果类似于左键点击),然后再弹出自定义的弹出菜单.急用,哪位好心人帮帮忙!貌似不太准啊,出现滚...
如题,当我在列表控件中(listbox)的某一行上点击右键时,先选定这一行(效果类似于左键点击),然后再弹出自定义的弹出菜单.
急用,哪位好心人帮帮忙!
貌似不太准啊,出现滚动条了的话……好像更不准了…… 展开
急用,哪位好心人帮帮忙!
貌似不太准啊,出现滚动条了的话……好像更不准了…… 展开
1个回答
展开全部
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
Const LB_ITEMFROMPOINT = &H1A9
Private Sub Form_Load()
For i = 0 To 100
List1.AddItem i
Next
End Sub
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim pos As Long, idx As Long
pos = X / Screen.TwipsPerPixelX + Y / Screen.TwipsPerPixelY * 65536
idx = SendMessage(List1.hWnd, LB_ITEMFROMPOINT, 0, ByVal pos)
' idx 即等于鼠标所在位置的选项
If idx < 65536 And Button = 2 Then
List1.ListIndex = idx
'PopupMenu Menu 弹出菜单
End If
End Sub
Private Sub Command1_Click()
Static i
i = i + 1
List1.AddItem "text" & i
End Sub
//修改版
Const LB_ITEMFROMPOINT = &H1A9
Private Sub Form_Load()
For i = 0 To 100
List1.AddItem i
Next
End Sub
Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim pos As Long, idx As Long
pos = X / Screen.TwipsPerPixelX + Y / Screen.TwipsPerPixelY * 65536
idx = SendMessage(List1.hWnd, LB_ITEMFROMPOINT, 0, ByVal pos)
' idx 即等于鼠标所在位置的选项
If idx < 65536 And Button = 2 Then
List1.ListIndex = idx
'PopupMenu Menu 弹出菜单
End If
End Sub
Private Sub Command1_Click()
Static i
i = i + 1
List1.AddItem "text" & i
End Sub
//修改版
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询