VB如何让text中的内容不可以复制(在线等!)

VB如何让text中的内容不可以复制(在线等!)帮下忙~~~
2024-11-17 09:49:58
推荐回答(3个)
回答1:

你可以用JS屏蔽 CTRL 和鼠标右键但是真要复制你也是不能左右的

回答2:

以下是代码

--------

新建一个模块,添加以下代码,注意一定要放在模块中
Option Explicit

Private Const GWL_WNDPROC = (-4)
Private Const WM_RBUTTONDOWN = &H204
Public Const WM_COPY = &H301

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 prevWndProc As Long

Private Function WndProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_COPY Then

Else
WndProc = CallWindowProc(prevWndProc, hWnd, Msg, wParam, lParam)
End If
End Function

Sub DisableCopy(TargetTextBox As TextBox)

prevWndProc = GetWindowLong(TargetTextBox.hWnd, GWL_WNDPROC)
SetWindowLong TargetTextBox.hWnd, GWL_WNDPROC, AddressOf WndProc

End Sub

--------------
然后再窗体代码中添加
Private Sub Form_Load()
DisableCopy Text1
End Sub

即可,text1是想要禁止复制的textbox

回答3:

请说的明确一点