Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to display read-only text in C#

Tags:

c#

winforms

Showing text in a Textbox that's got property Enabled set to false or read-only set to true produces black on grey text, which isn't very nice to read at all.

What's the easiest way to show read only text nicely in Windows Forms?

like image 432
Andrew Ducker Avatar asked Feb 12 '10 15:02

Andrew Ducker


People also ask

How do I make a TextBox read only?

Set the TextBox control's ReadOnly property to true . With the property set to true , users can still scroll and highlight text in a text box without allowing changes. A Copy command is functional in a text box, but Cut and Paste commands are not.

How do I make a field non editable in C#?

Use the ReadOnly property on the TextBox. When this property is set to true, the contents of the control cannot be changed by the user at runtime.

How do I make a TextBox not editable in VB net?

You can use either the ReadOnly or the Enable property of the TextBox control as suggested by other members above.. TextBox1. Enabled = false; Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM.


1 Answers

Can't you override the ForeColor and BackColor properties when it's locked?

Failing that, create your own textbox class that listens to the KeyUp event and intercepts the key press if the ReadOnly (or Locked) property is set to true (preventing it being added to the text.) Then you can use any styles you like.

like image 169
Andy Shellam Avatar answered Oct 05 '22 23:10

Andy Shellam