可以是下面这样 private sub text1_mousedown(button as integer) if button=2 then text1.enabled=false text1.enabled=true '这样就隐蔽了菜单,但keydown事件仍可发生 end if end sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) If Button = 2 Then Text1.Enabled = False Text1.Enabled = True Text1.SetFocus PopupMenu control '加入你自己的控件菜单 End If End Sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 Then MsgBox "norbutton", vbDefaultButton1 End IfEnd Sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 Then MsgBox "norbutton" End IfEnd Sub
;楼上的还要弹出一个对话框,另用户操作不方便,还是用这个 Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) If Button = 2 Then Text1.Enabled = False Text1.Enabled = True Text1.SetFocus PopupMenu control '加入你自己的控件菜单 End If End Sub
Option ExplicitPublic 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 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 Const GWL_WNDPROC = (-4)Public Const WM_RBUTTONDBLCLK = &H206 Public Const WM_RBUTTONDOWN = &H204 Public Const WM_RBUTTONUP = &H205Public prevWndProc As LongPublic 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_RBUTTONDBLCLK: Case WM_RBUTTONDOWN: Case WM_RBUTTONUP: Case Else WndProc = CallWindowProc(prevWndProc, hWnd, Msg, wParam, lParam) End Select End Function ------------------------- Option ExplicitPrivate Sub Form_Load() Me.Show prevWndProc = GetWindowLong(Text1.hWnd, GWL_WNDPROC) SetWindowLong Text1.hWnd, GWL_WNDPROC, AddressOf WndProc End SubPrivate Sub Form_Unload(Cancel As Integer) If prevWndProc <> 0 Then SetWindowLong Text1.hWnd, GWL_WNDPROC, prevWndProc prevWndProc = 0 End If End Sub ================== 上面的代码写入模块,下面的代码写入FORM1。
哪有那么复杂 Option Explicit Private Declare Sub ReleaseCapture Lib "user32" () Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As LongPrivate Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = vbRightButton Then ReleaseCapture SetCapture Me.hwnd End If End Sub
Private Sub Text1_OnMouseDown(...) if button = 2 then button = 0 End Sub
Private ClipStr As String '剪切板的内容'禁鼠标右键粘贴 Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single) If Button = 2 Then SetClip End SubPrivate Sub Text1_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single) If Button = 2 Then GetClip End Sub'禁键盘粘贴 Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer) If Shift = 2 And KeyCode = 86 Then '键盘上的CTRL+V KeyCode = 0 GetClip End If End SubPrivate Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer) If Shift = 2 And KeyCode = 86 Then KeyCode = 0 SetClip End If End Sub '取剪切板内容 Private Sub GetClip() If Clipboard.GetFormat(1) = True Then ClipStr = Clipboard.GetText Clipboard.Clear End If End Sub '设剪切板内容 Private Sub SetClip() If ClipStr <> "" And Clipboard.GetText = "" Then Clipboard.SetText ClipStr ClipStr = "" End If End Sub
private sub text1_mousedown(button as integer)
if button=2 then
text1.enabled=false
text1.enabled=true '这样就隐蔽了菜单,但keydown事件仍可发生
end if
end sub
If Button = 2 Then
Text1.Enabled = False
Text1.Enabled = True
Text1.SetFocus
PopupMenu control '加入你自己的控件菜单
End If
End Sub
If Button = 2 Then
MsgBox "norbutton", vbDefaultButton1
End IfEnd Sub
If Button = 2 Then
MsgBox "norbutton"
End IfEnd Sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = 2 Then
Text1.Enabled = False
Text1.Enabled = True
Text1.SetFocus
PopupMenu control '加入你自己的控件菜单
End If
End Sub
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 Const GWL_WNDPROC = (-4)Public Const WM_RBUTTONDBLCLK = &H206
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205Public prevWndProc As LongPublic 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_RBUTTONDBLCLK:
Case WM_RBUTTONDOWN:
Case WM_RBUTTONUP:
Case Else
WndProc = CallWindowProc(prevWndProc, hWnd, Msg, wParam, lParam)
End Select
End Function
-------------------------
Option ExplicitPrivate Sub Form_Load()
Me.Show
prevWndProc = GetWindowLong(Text1.hWnd, GWL_WNDPROC)
SetWindowLong Text1.hWnd, GWL_WNDPROC, AddressOf WndProc
End SubPrivate Sub Form_Unload(Cancel As Integer)
If prevWndProc <> 0 Then
SetWindowLong Text1.hWnd, GWL_WNDPROC, prevWndProc
prevWndProc = 0
End If
End Sub
==================
上面的代码写入模块,下面的代码写入FORM1。
Option Explicit
Private Declare Sub ReleaseCapture Lib "user32" ()
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As LongPrivate Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
ReleaseCapture
SetCapture Me.hwnd
End If
End Sub
或者不响应
这样就可以了
不要把enable设置为false
否则不能用Ctrl +V
if button = 2 then button = 0
End Sub
Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single)
If Button = 2 Then SetClip
End SubPrivate Sub Text1_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single)
If Button = 2 Then GetClip
End Sub'禁键盘粘贴
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = 2 And KeyCode = 86 Then '键盘上的CTRL+V
KeyCode = 0
GetClip
End If
End SubPrivate Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
If Shift = 2 And KeyCode = 86 Then
KeyCode = 0
SetClip
End If
End Sub
'取剪切板内容
Private Sub GetClip()
If Clipboard.GetFormat(1) = True Then
ClipStr = Clipboard.GetText
Clipboard.Clear
End If
End Sub
'设剪切板内容
Private Sub SetClip()
If ClipStr <> "" And Clipboard.GetText = "" Then
Clipboard.SetText ClipStr
ClipStr = ""
End If
End Sub
放假回来了,看到大家的留言,感谢
试了大家的方法,总结如下:dongge2000(※秋日私语※:非[版务].灌!) 的方法可行,禁止了右键菜单,同时Ctrl_V可以粘贴Tiger_Zhao(VB老鸟)的方法可以理解,但是不知为何出错laihongbo524(风铃夜思雨)的方法禁止了右键粘贴,但也禁止了Ctrl_V,我把禁键盘那段拿掉,就可以了:)所以也可行其他方法未试成功结贴,非常感谢各位!