Changing TextBox BackColor / ForeColor When Disabled

  • Thread starter Thread starter Steve Le Monnier
  • Start date Start date
S

Steve Le Monnier

When you make a textbox control disabled ( txtText1.Enabled = false; )

You're left with grey text on a greyer background, which is not ideal. The
Read-Only property is no use to me as I need to prevent complete access, so
i've been trying to change the visual display of a control once I have
disabled it and discovered the following.

You can change the back color of a disabled control. (txtText1.BackColor =
System.Drawing.SystemColors.Window;) which improves readability, but I can't
change the forecolor of the control!

Does anybody know why and more importantly how can I change this behaviour
to prevent disabled controls being grey on greyer.

Many thanks

Steve Le Monnier
 
Steve,

The most simple method that came in my mind is hide the textbox and show a
label with the same text on that place.

Cor
 
I havent seen a solution to this problem which I have seen asked before (
Though there propably is one somewhere ). But there are several alternative
approaches. you could take.

One approach might be to create a user control with a public property to
enable or disable the control. Then you could have a text property to set a
label and text box simeltaniously. The basic idea is that the two controls
would switch visability depending on if the control was enabled.

HTH
 
hi,

AFAIK there is no way of doing it, you would have either subclass the
textbox and handle the onpaint you self or when the textbox is disabled
change it for other control, like a Label.

no idea even if this is allowed in 2.0 , will check though.

cheers,
 
Back
Top