MSMVPS.COM
The Ultimate Destination for Blogs by Current and Former Microsoft Most Valuable Professionals.

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 .
 

Posted Nov 03 2003, 01:28 PM by ch21st

Comments

ch21st wrote re: Preventing a User from Editing the Contents of a Text Box Control
on 01-16-2004 23:15
hi! is there some workaround?
thanx

Add a Comment

(required)  
(optional)
(required)  
Remember Me?


Copyright © is the original authors. Blog site is an independent site not sponsored by Microsoft. The Yoda blog server and the Brianna SQL server would like to thank www.ownwebnow.com and www.exchangedefender.com. They wouldn't be here and broadcasting without the generosity of Vlad Mazek and his companies.

Powered by Community Server (Commercial Edition), by Telligent Systems