永发信息网

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

答案:6  悬赏:0  手机版
解决时间 2021-05-06 09:36
  • 提问者网友:最爱你的唇
  • 2021-05-06 03:23

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

帮下忙~~~

最佳答案
  • 五星知识达人网友:刀戟声无边
  • 2021-05-06 04:33
以下是代码

--------

新建一个模块,添加以下代码,注意一定要放在模块中
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
全部回答
  • 1楼网友:老鼠爱大米
  • 2021-05-06 09:13
你可以用定时器把剪贴板内容随时清空
  • 2楼网友:人间朝暮
  • 2021-05-06 07:40
在编辑框上画个透明标签盖着再给与透明标签焦点
  • 3楼网友:渡鹤影
  • 2021-05-06 06:53

一个timer1 一个text1 复制以下代码进去 不是很完美,但可以达到目的,谢谢采纳

Private Const MOD_Ctrl = &H2 Private Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long Private Sub Form_Load() a = RegisterHotKey(Me.hwnd, 1, MOD_Ctrl, vbKeyC) Timer1.Enabled = False Timer1.Interval = 200 End Sub Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If (Button And 2) = 2 Then Timer1.Enabled = True End Sub Private Sub Timer1_Timer() SendKeys "{esc}" Timer1.Enabled = False End Sub

  • 4楼网友:掌灯师
  • 2021-05-06 06:36

你可以用JS屏蔽 CTRL 和鼠标右键

但是真要复制你也是不能左右的

<script language="javascript">

function click(e) {    if (document.all) {    if (event.button==1||event.button==2||event.button==3) {     oncontextmenu='return false';    }    }    if (document.layers) {    if (e.which == 3) {     oncontextmenu='return false';    }    }   }   if (document.layers) {    document.captureEvents(Event.MOUSEDOWN);   }   document.onmousedown=click;   document.oncontextmenu = new Function("return false;")

  var travel=true   var hotkey=17    if (document.layers)   document.captureEvents(Event.KEYDOWN)   function gogo(e)   { if (document.layers) {   if (e.which==hotkey&&travel){    alert("操作错误.或许是您按错了按键!"); } }   else if (document.all){   if (event.keyCode==hotkey&&travel){ alert("操作错误.或许是您按错了按键!"); }}   }

  document.onkeydown=gogo

</script>

  • 5楼网友:玩世
  • 2021-05-06 05:48
请说的明确一点
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯