TextBox question...

ALX

Well-known member
Joined
Nov 16, 2005
Messages
253
Location
Columbia, SC
Programming Experience
10+
Is it possible to make a textbox behave as a label for those times when you want to disallow any input to the textbox without disabling the textbox? ... or maybe a better way to ask... can you make the textbox APPEAR the same disabled as it appears enabled ? I don't want the dim gray color tones when disabled since my textboxes still convey information when not active as an input method.
 
textbox's do have a ReadOnly property, just change it to True and the user can still highlight and copy information but can't type anything in

once you set the ReadOnly property to true the textbox's background colour does change to gray but you can set it back to white if ya need:
VB.NET:
Textbox1.ReadOnly = True
Textbox1.BackColor = SystemColors.Window
 
That was a good simple fix & I'm embarrased that I couldn't figure that out on my own... but one more issue on this subject....If the user clicks on the textbox (when in Read only mode) a caret appears in the textbox that could be distracting. Is there a way to get rid of the caret ?
 
Last edited:
Yes, I did. That does get rid of the caret but changes the forecolor to gray. So far, the only way that I've been able to pull this off is by creating a dummy textbox that is hidden behind some other component (or label), and redirecting the focus to the dummy textbox when the user clicks on the real textbox. This seems a little tacky and inefficient to me. I was just hoping to find a better way.
 
Last edited:
VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].TextBox1.ReadOnly = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].TextBox1.BackColor = SystemColors.Control
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].TextBox1.BorderStyle = BorderStyle.None
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].TextBox1.ForeColor = SystemColors.WindowText
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].TextBox1.Cursor = System.Windows.Forms.Cursors.Default
[/SIZE]
 
VB.NET:
[COLOR=#0000ff]Me[/COLOR][SIZE=2].TextBox1.Cursor = System.Windows.Forms.Cursors.Default [/SIZE]
sets the cursor for the mouse. I'm trying to get rid of the text caret which, of course, is the blinking line in the textbox that shows where input text will be inserted.
 
See my attached project below. Its a custom made textbox. In the 'GetBitmaps' sub you will see down the bottom of it is the part of the code that actually draws the caret. You could wrap a property around this and only draw it if you want to.
 

Attachments

  • LightningControlsSE.zip
    47.2 KB · Views: 76
Back
Top