Solved

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

Posted on 1998-08-30
4
569 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
ID: 1431970
What is the Question?
0
 
LVL 9

Accepted Solution

by:
Dalin earned 50 total points
ID: 1431971
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
ID: 1431972
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
ID: 1431973
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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA error replacing data 6 40
Access query that references subform 5 47
VBA: Personal Macro Retain/Highlight/Remove values in a selected column 4 30
VB6 ListBox Question 4 44
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 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