Shannon Shang-I think therefore I am

We came here, you and I, to this place and this profession, to be great, to do great things, and give form to great dreams - and we have

Preventing a User from Editing the Contents of a Text Box Control

Reference “Tip 135: Preventing a User from Editing the Contents of a Text Box Control“ and “Knowledge Base Q110403“

We can get the fellowing information in that articles :

you might not want your user to be able to edit the text that is stored in the Text Box control. You can set the contents of a Text Box control to read-only status by using the Microsoft Windows® programming application interface (API) SendMessage function.

The SendMessage function can be used to send an EM_SETREADONLY message to the Text Box control. This makes the Text Box control read-only.

Code Example:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" 
   (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, 
   ByVal lParam As Long) As Long
Private Const EM_SETREADONLY = &HCF
Private Sub Command1_Click()
    Dim RetVal As Long
    RetVal = SendMessage(Text1.hwnd, EM_SETREADONLY, True, ByVal 0&)
End Sub
Run this example,the Text of Text1 will can't be edited,but it has a bug ,in this time ,user still can edit the text of Text1 by clicking the “Paste”submenu in Context Menu to paste text in clipboard to this Textbox .
 

Comments

ch21st said:

hi! is there some workaround?
thanx
# January 16, 2004 11:15 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)