Niko Gamulin Niko Gamulin - 28 days ago 17
C# Question

How to change the font color of a disabled TextBox?

Does anyone know which property sets the text color for disabled control?
I have to display some text in a disabled

TextBox
and I want to set its color to black.

Answer

NOTE: see Cheetah's answer below as it identifies a prerequisite to get this solution to work. Setting the BackColor of the TextBox.


I think what you really want to do is enable the TextBox and set the ReadOnly property to true.

It's a bit tricky to change the color of the text in a disabled TextBox. I think you'd probably have to subclass and override the OnPaint event.

ReadOnly though should give you the same result as !Enabled and allow you to maintain control of the color and formatting of the TextBox. I think it will also still support selecting and copying text from the TextBox which is not possible with a disabled TextBox.

Another simple alternative is to use a Label instead of a TextBox.

Comments