I’m writing a WinForms application. I have many labels which represent some status (Enabled/Disabled etc). I want each status to be different color (green, grey…).
The only way I know to achive this is to check whether label.Text matches required status and then change its ForeColor. But this is a hard way, as I need to perform this check every time I set status label in my application.
I wonder if there is any way to do it “in one place?”.
For example writing a method that will check all labels for specific string and just call it from Form_Load()
Enumerate all labels on Form using Form Controls and it’s child controls, for example use GetAll method from this SO answer :
How to get ALL child controls of a Windows Forms form of a specific type (Button/Textbox)?
And then set appropriate color, something like this :