vb鼠标右键双击事件
发布网友
发布时间:2022-05-01 10:02
我来回答
共5个回答
热心网友
时间:2023-10-07 14:46
先说明几点:
1.不是所有的对象,都有双击事件(zhangfeizimo在前面说过了)
2.支持双击事件的对象,在触发这个事件时,并不识别是不是右键
3.能识别右键的事件,不区分是单击还是双击
所以,如果用系统的自带单一事件,是不能直接完成你想的目的
不过,可以变通,将几个事件结合起来,就可以实现,看看下面的方法:
Dim LastButton As Integer
Private Sub Form_DblClick()
If LastButton = 2 Then
Text1.Text = 2
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
LastButton = Button
End Sub
热心网友
时间:2023-10-07 14:46
屏蔽TEXT1右键菜单,利用计时器判断是否双击:
form1里代码:
Option Explicit
Private blnF As Boolean
Private Sub Command1_Click()
Text1 = ""
End Sub
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = False
End Sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
OldWindowProc = GetWindowLong(Text1.hWnd, GWL_WNDPROC)
Call SetWindowLong(Text1.hWnd, GWL_WNDPROC, AddressOf MyMesg)
If blnF Then Text1 = "右键双击": blnF = False: Timer1.Enabled = False: Exit Sub
blnF = True '设置右键检查标志
Timer1.Enabled = True
Else
Text1 = "右键未双击"
blnF = False
End If
End Sub
Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then
Button = 1
Call SetWindowLong(Text1.hWnd, GWL_WNDPROC, OldWindowProc)
End If
End Sub
Private Sub Timer1_Timer()
blnF = False
Timer1.Enabled = False
Text1 = "右键单击"
End Sub
Mole1里代码:
Option Explicit
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public OldWindowProc As Long
Public Const WM_CONTEXTMENU = &H7B
Public Const GWL_WNDPROC = (-4)
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Function MyMesg(ByVal hWnd As OLE_HANDLE, ByVal Msg As OLE_HANDLE, ByVal wp As OLE_HANDLE, ByVal lp As Long) As Long
If Msg <> WM_CONTEXTMENU Then
MyMesg = CallWindowProc(OldWindowProc, hWnd, Msg, wp, lp)
Exit Function
End If
MyMesg = True
End Function
热心网友
时间:2023-10-07 14:46
可以在MOUSEUP事件里面进行右键的判断然后累加。
另外设置一个1秒的定时器定时给累加的数归零。
当累加的数便为2是,调用一个过程,这个过程自定义。
这个过程就是要发生的右键双击的事件。
热心网友
时间:2023-10-07 14:47
事件里选中Double click然后再赋值
热心网友
时间:2023-10-07 14:48
尽量不要出现右键双击,左键双击就好啦
!11
1
1
1
!