Read Only Text Boxes

by Stephan Grieger - GUI Computing

In the last edition, I published an article which enabled you to change the text colour of a Textbox when the Textbox has been disabled. While this was a cute solution to a problem that's plagued many people for a long time, itís probably not the best solution as it required constant tending when the screen was refreshed.

If you are having trouble keeping the text un-greyed then try sending the text box a read only message. Doing this will not only set the control for read only, but it will also not grey the text. The API call used is SendMessage and the entire code requires one line.

  er% = SendMessage(Text1.hWnd,&H400 + 31, True, 0&)

Once run, the text box will no longer accept any keystrokes. The added bonus is that you can still scroll up and down through the text box if it is set to multi line, unlike the .Enabled method. The downside of this is that if the user clicks on the text box, the cursor will still flash inside the control giving the user the impression that they can type information in. To re-enable keyboard entry set the True flag to False and re-run the line.


Written by: Stephan Grieger
August 1995

Image of arrow to previous article Image of arrow to next article

[HOME] [TABLE OF CONTENTS] [SEARCH]