Solved

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

Posted on 1998-08-30
4
567 Views
Last Modified: 2012-06-21
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.
0
Comment
Question by:Richard2000
  • 2
4 Comments
 
LVL 3

Expert Comment

by:a111a111a111
Comment Utility
What is the Question?
0
 
LVL 9

Accepted Solution

by:
Dalin earned 50 total points
Comment Utility
Richard2000,


Set the locked property to true, and in the textbox's gotfocus event add:
command1.setfocus

You can replace command1 with the name of the control that you like it to receive focus.

0
 

Expert Comment

by:mskannan
Comment Utility
Hi Richard,
In the keypress event of the testbox, just type
keyascii = 0
This will  give you the solution for your problem
Regards,
mskannan
0
 
LVL 9

Expert Comment

by:Dalin
Comment Utility
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
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now