vb6.0里面如何右键单击文本框弹出菜单项
答案:2 悬赏:80 手机版
解决时间 2021-03-22 23:20
- 提问者网友:世勋超人
- 2021-03-22 08:51
vb6.0里面如何右键单击文本框弹出菜单项
最佳答案
- 五星知识达人网友:一把行者刀
- 2021-03-22 09:41
Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then PopupMenu mnu_mymenu
End Sub
mnu_mymenu 就是使用菜单编辑器设置的 第一层名称(设置在该次层的名称标题都会出现)
第一层名称的“标题”可以随便写,(这个标题设置为隐藏、“可见”选项不要打勾)
If Button = vbRightButton Then PopupMenu mnu_mymenu
End Sub
mnu_mymenu 就是使用菜单编辑器设置的 第一层名称(设置在该次层的名称标题都会出现)
第一层名称的“标题”可以随便写,(这个标题设置为隐藏、“可见”选项不要打勾)
全部回答
- 1楼网友:第幾種人
- 2021-03-22 10:19
楼上的会先弹出系统菜单再弹出自己的菜单,所以要先屏蔽系统菜单,首先要拦截右键信息,新建一个模块
Option ExplicitPrivate Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private 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
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_WNDPROC = (-4)
Private Const WM_CONTEXTMENU = &H7B '-------------右键菜单
Private prevWndProc As Long
Private Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
Case WM_CONTEXTMENU
'这里处理自定义的事件,最好为空
Case Else
'回调系统函数处理
WndProc = CallWindowProc(prevWndProc, hwnd, Msg, wParam, lParam)
End Select
End Function
Public Sub DisableAbility(TargetTextBox As TextBox)
prevWndProc = GetWindowLong(TargetTextBox.hwnd, GWL_WNDPROC)
SetWindowLong TargetTextBox.hwnd, GWL_WNDPROC, AddressOf WndProc
End Sub
然后在你的form窗体里写入
DisableAbility Text1'屏蔽系统右键
End Sub
Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then PopupMenu rrr'假设自己的菜单是rrr,弹出自己的菜单
End Sub
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯