VB6中如何实现不能复制,粘贴动作TEXTBOX内的文本?
文本框的内容需要用滑动条拖动查看,但是不希望内容被复制。谢谢各位高手将textbox的locked属性设成true.这个参数只是锁定不能修改文本框内的内容,但是可以被复制...
文本框的内容需要用滑动条拖动查看,但是不希望内容被复制。谢谢各位高手
将textbox的locked属性设成true.这个参数只是锁定不能修改文本框内的内容,但是可以被复制粘贴。
将textbox的enabled属性设成false
textbox1.enabled=false。整个文本框不可操作,滑动条也无效了,不能查看文本框里的内容。 展开
将textbox的locked属性设成true.这个参数只是锁定不能修改文本框内的内容,但是可以被复制粘贴。
将textbox的enabled属性设成false
textbox1.enabled=false。整个文本框不可操作,滑动条也无效了,不能查看文本框里的内容。 展开
5个回答
展开全部
'很明显这个只能用HOOK来解决,但楼主忽视我的的答案,不知道是不会用还是?10分的题送了个100分的答案给你,如果真的是不懂用还想得通,否则楼主就有点太贪了。
'新建工程,添加一个窗体,一个模块
'窗体上添加一个TextBox控件,名字使用默认名称就可以了。
'==================================================
'窗体中代码
'==================================================
Option Explicit
Private Sub Form_Load()
Hook Text1.hWnd
Text1.Text = Text1.Text & vbCrLf & Text1.Text
End Sub
'==================================================
'模块中代码
'==================================================
Option Explicit
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 SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const GWL_WNDPROC = (-4)
Dim OldProc As Long
Dim mhWnd As Long
'==================================================
'回调
Public Function WinProc(ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
'不允许复制,但允许粘贴用下面这条,注意:两条IF只能用一条。
'If wMsg <> &H301 Then WinProc = CallWindowProc(OldProc, hWnd, wMsg, wParam, lParam)
'不允许复制、粘贴用下面这条
If (wMsg <> &HC2) And (wMsg <> &H301) Then WinProc = CallWindowProc(OldProc, hWnd, wMsg, wParam, lParam)
End Function
'==================================================
'==================================================
'挂钩
Sub Hook(ByVal nhWnd As Long)
mhWnd = nhWnd
OldProc = SetWindowLong(nhWnd, GWL_WNDPROC, AddressOf WinProc)
End Sub
'==================================================
'==================================================
'脱钩
Sub UnHook()
If OldProc = 0 Then Exit Sub
SetWindowLong mhWnd, GWL_WNDPROC, OldProc
OldProc = 0
End Sub
'==================================================
'新建工程,添加一个窗体,一个模块
'窗体上添加一个TextBox控件,名字使用默认名称就可以了。
'==================================================
'窗体中代码
'==================================================
Option Explicit
Private Sub Form_Load()
Hook Text1.hWnd
Text1.Text = Text1.Text & vbCrLf & Text1.Text
End Sub
'==================================================
'模块中代码
'==================================================
Option Explicit
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 SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const GWL_WNDPROC = (-4)
Dim OldProc As Long
Dim mhWnd As Long
'==================================================
'回调
Public Function WinProc(ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
'不允许复制,但允许粘贴用下面这条,注意:两条IF只能用一条。
'If wMsg <> &H301 Then WinProc = CallWindowProc(OldProc, hWnd, wMsg, wParam, lParam)
'不允许复制、粘贴用下面这条
If (wMsg <> &HC2) And (wMsg <> &H301) Then WinProc = CallWindowProc(OldProc, hWnd, wMsg, wParam, lParam)
End Function
'==================================================
'==================================================
'挂钩
Sub Hook(ByVal nhWnd As Long)
mhWnd = nhWnd
OldProc = SetWindowLong(nhWnd, GWL_WNDPROC, AddressOf WinProc)
End Sub
'==================================================
'==================================================
'脱钩
Sub UnHook()
If OldProc = 0 Then Exit Sub
SetWindowLong mhWnd, GWL_WNDPROC, OldProc
OldProc = 0
End Sub
'==================================================
展开全部
将textbox的locked属性设成true.
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
将textbox的enabled属性设成false
textbox1.enabled=false
textbox1.enabled=false
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用Label模拟TextBox
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没必要那么复杂~~
使用剪贴板对象就可以做到了!
使用剪贴板对象就可以做到了!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询