Hi,
Does anyone know which property sets the text color for disabled control? I have to display some text in disabled TextBox and I want to set its color to black.
Thanks!
Hi,
Does anyone know which property sets the text color for disabled control? I have to display some text in disabled TextBox and I want to set its color to black.
Thanks!
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
.
Additionally, in order for ForeColor to be obeyed on a TextBox marked ReadOnly, you must explicitly set the BackColor. If you want to have it still use the default BackColor, you have to make the set explicit, as the designer is too smart for its own good here. It is sufficient to set the BackColor to its current value. I do this in the Load event for the form, like so:
private void FormFoo_Load(...) {
txtFoo.BackColor = txtFoo.BackColor;
}