0
votes

I am working on on a winforms C# application and want to give the user an option to change the colour of the form background and text throughout the application.

The application contains panels, labels, textboxes etc.

One way I thought of was to store the user preference as the colours RGB value and have the form set it when the form loads for all the various controls. But this way seems a bit laboured.

Is there an easier or more effective way of achieving this?

1
Application settings allow you to store a color object easily - logix
That's the easy bit....the hard bit I am trying to figure out is how to apply it to the controls across the app (forms, user controls etc). - Adrian Brown
If you write a function that recursively walks the .Controls collection of every control, you can pass everything that exists on each form in to a function on Load that reads the Control type, and sets property values from the settings. for dynamically created controls, you can just have a factory like var textBox = ControlFactory.Create<TextBox>(); that does the same thing. That factory could even return Decorated versions if you want to do something totally custom. - Bradley Uffner
You can use property binding to application settings. Take a look at this post for example. Then use a PropertyGrid control to edit the Settings class at run-time. - Reza Aghaei
You aren't worried about how to store/retrieve if I understand correctly, you are worried with how to automatically apply the stored settings without doing anything when you create a new instance of a form, correct? Load settings in on application start, and then every form thereafter uses those settings on itself? - Aaron

1 Answers

0
votes

In my opinion, the easier way to do this is to use settings file in winform which will keep user data in a file and recalls it at anytime. You can follow this link to implement this demo

You only have to create one class that handles the theme. You can automate it.