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 LongPrivate Const GWL_STYLE = (-16) Private Const ES_MULTILINE = &H4& Private Const ES_AUTOVSCROLL = &H40& Private Const ES_AUTOHSCROLL = &H80&dim lStyle as long lStyle = GetWindowLong(txtEdit.hwnd, GWL_STYLE) lStyle = lStyle Or ES_MULTILINE Or ES_AUTOHSCROLL Or ES_AUTOVSCROLL
SetWindowLong txtEdit.hwnd, GWL_STYLE, lStyle
更新一下: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 LongPrivate Const GWL_STYLE = (-16) Private Const WS_VSCROLL = &H200000 Private Const WS_HSCROLL = &H100000 Private Const ES_MULTILINE = &H4& Private Const ES_AUTOVSCROLL = &H40& Private Const ES_AUTOHSCROLL = &H80&dim lStyle as long lStyle = GetWindowLong(txtEdit.hwnd, GWL_STYLE) lStyle = lStyle Or ES_MULTILINE Or WS_HSCROLL Or ES_AUTOHSCROLL Or WS_VSCROLL Or ES_AUTOVSCROLL
SetWindowLong txtEdit.hwnd, GWL_STYLE, lStyle
锁定它,使它不能编辑就行 把它的locked的属性设为true就行了
Option ExplicitPrivate 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 LongPrivate Const GWL_STYLE = (-16) Private Const ES_READONLY = &H2000& Private Const ES_MULTILINE = &H4& Private Sub Command1_Click() Text1 = "fadsfads" End SubSub Form_Load() Dim iStyle As Long iStyle = GetWindowLong(Text1.hwnd, GWL_STYLE) iStyle = iStyle Or ES_READONLY Or ES_MULTILINE
SetWindowLong Text1.hwnd, GWL_STYLE, iStyle End Sub
text1.locked=false '取消只读
除非你自己做一个ActiveX控件,或者把这个控件隐藏,显示另一个控件。
实在要这样的控件就只能自己编了.
直接把textbox的enabel属性设置为false
这样就避免了更改!
不知道对不对?!
不过……,有必要这样吗?
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPrivate Const GWL_STYLE = (-16)
Private Const ES_MULTILINE = &H4&
Private Const ES_AUTOVSCROLL = &H40&
Private Const ES_AUTOHSCROLL = &H80&dim lStyle as long lStyle = GetWindowLong(txtEdit.hwnd, GWL_STYLE)
lStyle = lStyle Or ES_MULTILINE Or ES_AUTOHSCROLL Or ES_AUTOVSCROLL
SetWindowLong txtEdit.hwnd, GWL_STYLE, lStyle
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPrivate Const GWL_STYLE = (-16)
Private Const WS_VSCROLL = &H200000
Private Const WS_HSCROLL = &H100000
Private Const ES_MULTILINE = &H4&
Private Const ES_AUTOVSCROLL = &H40&
Private Const ES_AUTOHSCROLL = &H80&dim lStyle as long lStyle = GetWindowLong(txtEdit.hwnd, GWL_STYLE)
lStyle = lStyle Or ES_MULTILINE Or WS_HSCROLL Or ES_AUTOHSCROLL Or WS_VSCROLL Or ES_AUTOVSCROLL
SetWindowLong txtEdit.hwnd, GWL_STYLE, lStyle
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As LongPrivate Const GWL_STYLE = (-16)
Private Const ES_READONLY = &H2000&
Private Const ES_MULTILINE = &H4&
Private Sub Command1_Click()
Text1 = "fadsfads"
End SubSub Form_Load()
Dim iStyle As Long iStyle = GetWindowLong(Text1.hwnd, GWL_STYLE)
iStyle = iStyle Or ES_READONLY Or ES_MULTILINE
SetWindowLong Text1.hwnd, GWL_STYLE, iStyle
End Sub
可以文本框编写文本框的keypress事件,使它不接受外来的事件,不知道行不行.