Home > Mobile >  How can I set a c# TextBox to disabled but still have the original text styling instead of grayed ou
How can I set a c# TextBox to disabled but still have the original text styling instead of grayed ou

Time:08-09

So for the program I'm writing I have an overview of notes the user created. This I created with TextBoxes that are generated from database values. I want the user to not be able to enter and change anything in this overview.
I tried to use tb.ReadOnly = true; but this doesn't disable the entering of the textbox.
After that I tried tb.Enabled = false; but this applies a gray out to all the text.

Is there any way to remove this gray out or just make the TextBox unchangeable without any visual difference?

CodePudding user response:

Create a label with border style as FixedSingle, flat style as Flat, and set padding to 5,5,5,5.

CodePudding user response:

One option is to use a NuGet package such as Guna UI to add custom controls. Using Guna, you can use the Control.DisabledState:

textBox1.DisabledState.FillColor = Color.White;
textBox1.DisabledState.ForeColor = Color.Black;

Note: changing a UI control's disabled state to make it appear enabled is in general, bad practice. This is because a user may try to use the TextBox and get frustrated because the computer will not let them use it.

Or alternatively, you could use a Label instead of a TextBox.

  • Related