Change TextColor of disabled control

How to change text color when a control is disabled. I want to set a different color when control is disabled in winforms C #.

+4
source share
3 answers

Edit: I made the same mistake as Cody in the comments, so I corrected my answer.

It depends on what kind of control he has.

For example, if it is a TextBox , perhaps you can make it ReadOnly instead of disabled. And for some other controls, you could do things like this to make them seem to be disabled without actually disconnecting.

However, if you want to do this correctly, you need to make them the owner or override the OnPaint event and draw the text yourself.

+3
source

You can just do it manually - when you turn off the control, just change the color of the text?

+1
source

If you have many controls, you can do this:

  • Attach your form to the OnChildAdded event
  • if used, if ... has a type structure for determining the type of control
  • Depending on the type of control, register the appropriate OnEnabledChange event
  • in case of text color change

Thus, you will have a piece of code that will work for all your forms and will gradually expand to use all the controls you need.

I have provided some code if this is the way you want ...

0
source

All Articles