更多请参考http://community.csdn.net/Expert/topic/3649/3649442.xml?temp=.95833994. 设置TEXTBOX为只读属性 Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd _ As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd _ As Long, ByVal nIndex As Long) As Long Private Const GWL_STYLE = (-16) Private Const EM_SETREADONLY = &HCF Private Sub Command1_Click() Dim l As Long If (GetWindowLong(Text1.hwnd, GWL_STYLE) And &H800) Then Text1.Text = "This is a read/write text box." '文本窗口是只读窗口,设置为可读写窗口 l = SendMessage(Text1.hwnd, EM_SETREADONLY, False, vbNull) Text1.BackColor = RGB(255, 255, 255) '将背景设置为白色 Command1.Caption = "Read&Write" Else Text1.Text = "This is a readonly text box." '文本窗口是可读写窗口,设置为只读窗口 l = SendMessage(Text1.hwnd, EM_SETREADONLY, True, vbNull) Text1.BackColor = vbInactiveBorder '将背景设置为灰色 Command1.Caption = "&ReadOnly" End If End Sub
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd _
As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd _ As Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const EM_SETREADONLY = &HCF
Private Sub Command1_Click()
Dim l As Long
If (GetWindowLong(Text1.hwnd, GWL_STYLE) And &H800) Then
Text1.Text = "This is a read/write text box." '文本窗口是只读窗口,设置为可读写窗口
l = SendMessage(Text1.hwnd, EM_SETREADONLY, False, vbNull)
Text1.BackColor = RGB(255, 255, 255) '将背景设置为白色
Command1.Caption = "Read&Write"
Else
Text1.Text = "This is a readonly text box." '文本窗口是可读写窗口,设置为只读窗口
l = SendMessage(Text1.hwnd, EM_SETREADONLY, True, vbNull)
Text1.BackColor = vbInactiveBorder '将背景设置为灰色
Command1.Caption = "&ReadOnly"
End If
End Sub