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.

- 4,206
- 4
- 21
- 39

- 66,025
- 95
- 221
- 286
-
3answer from Cheeta is correct. Consider reflagging? – Dec 17 '09 at 21:22
9 Answers
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
.

- 47,184
- 49
- 157
- 202
-
-
-
that's true, feel free to change it to a more exact answer if one pops up. – Eric Schoonover Nov 10 '08 at 18:57
-
-
This only works if you want the color black. It still won't let you use the Foreground property to control the color. – giltanis Jul 26 '13 at 19:59
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;
}

- 1,141
- 11
- 21
-
5IIRC, there is a flag somewhere to check if the colors have been customized. That flag doesn't get set unless the BackColor is set. I can't find it now, but if you rummage around in Reflector, you might be able to. – Cheetah Jan 07 '11 at 16:01
I've just found a great way of doing that. In my example I'm using a RichTextBox but it should work with any Control:
public class DisabledRichTextBox : System.Windows.Forms.RichTextBox
{
// See: http://wiki.winehq.org/List_Of_Windows_Messages
private const int WM_SETFOCUS = 0x07;
private const int WM_ENABLE = 0x0A;
private const int WM_SETCURSOR = 0x20;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if (!(m.Msg == WM_SETFOCUS || m.Msg == WM_ENABLE || m.Msg == WM_SETCURSOR))
base.WndProc(ref m);
}
}
You can safely set Enabled = true and ReadOnly = false, and it will act like a label, preventing focus, user input, cursor change, without being actually disabled.
See if it works for you. Greetings

- 1,469
- 2
- 21
- 32
hi set the readonly attribute to true from the code side or run time not from the design time
txtFingerPrints.BackColor = System.Drawing.SystemColors.Info;
txtFingerPrints.ReadOnly = true;

- 51
- 1
- 1
You can try this. Override the OnPaint event of the TextBox.
protected override void OnPaint(PaintEventArgs e)
{
SolidBrush drawBrush = new SolidBrush(ForeColor); //Use the ForeColor property
// Draw string to screen.
e.Graphics.DrawString(Text, Font, drawBrush, 0f,0f); //Use the Font property
}
set the ControlStyles to "UserPaint"
public MyTextBox()//constructor
{
// This call is required by the Windows.Forms Form Designer.
this.SetStyle(ControlStyles.UserPaint,true);
InitializeComponent();
// TODO: Add any initialization after the InitForm call
}
Or you can try this hack
In Enter event set the focus
int index=this.Controls.IndexOf(this.textBox1);
this.Controls[index-1].Focus();
So your control will not focussed and behave like disabled.

- 15,535
- 14
- 95
- 108
If you want to display text that cannot be edited or selected you can simply use a label

- 11
- 1
In addition to the answer by @spoon16 and @Cheetah, I always set the tabstop
property to False on the textbox to prevent the text from being selected by default.
Alternatively, you can also do something like this:
private void FormFoo_Load(...) {
txtFoo.Select(0, 0);
}
or
private void FormFoo_Load(...) {
txtFoo.SelectionLength = 0;
}

- 2,744
- 2
- 35
- 44
-
Setting TabStop to false is important to avoid read only control accidentally getting focus. – Mike Paisner Aug 15 '20 at 22:48
Just handle Enable changed and set it to the color you need
private void TextBoxName_EnabledChanged(System.Object sender, System.EventArgs e)
{
((TextBox)sender).ForeColor = Color.Black;
}

- 3,387
- 2
- 25
- 39

- 144
- 1
- 5