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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With