有时我们需要在listbox的某个项目上右击然后弹出菜单来操作指定项,可是右击某一条时它并没有呈现选中状态,只有左键单击才可以,这显然不符合我们要求的,不过我们用个api函数稍稍处理下即可,很方便实用。
Option Explicit 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 ' left button down Private Const MOUSEEVENTF_LEFTUP = &H4 ' left button up Private Sub Form_Load() Dim i% For i = 1 To 5 List1.AddItem i Next End Sub Private Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 Then mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0 mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 End If End Sub