Link to home
Start Free TrialLog in
Avatar of Richard2000
Richard2000

asked on

How can I make a read-only TextBox or RichTextBox?

I am using TextBoxes and RichTextBoxes for display only purposes and want to be able to make them read-only.  The user must not be able to interact with the control in any way (not even be able to select text or move the cursor inside), EXCEPT, if the box is too small to display all of the information, the user must still be able to use the scroll bars.

There are two simple ways in VB to do something similar, but both are unsatisfactory...

1) Set Locked property to true - This makes the control read-only, however the user can still select text, move the cursor within the control etc.  I don't want this functionality.

2) Set Enabled property to false - This make the control "read-only" too, but the control becomes grayed out making it more difficult to see.  Also, the user can't access the scoll bars.

I'm using VB 4 Enterprise Edition.  Maybe this behaviour could be achieved by issuing 1 or more Windows messages to the control using SendMessage()?  Thanks for your help.
Avatar of a111a111a111
a111a111a111

What is the Question?
ASKER CERTIFIED SOLUTION
Avatar of Dalin
Dalin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Richard,
In the keypress event of the testbox, just type
keyascii = 0
This will  give you the solution for your problem
Regards,
mskannan
mskanan,
Not realy. The user can highlight part or all the test with the mouse, and cut/copy/paste from the menu if there is one.
Regards
Dalin