A lightweight and flexible theme manager for WinForms applications β written entirely in C#, packed into a single .cs file.
Easily switch between Dark and Light modes, and apply custom styling to any control with full control over properties like BackColor, ForeColor, Font, BorderColor, Text, and more.
- β Supports any WinForms control β including third-party controls like Guna.UI2,...
- π¨ Apply theme-specific values for multiple properties (Color, Font, int, bool, string...)
- π Validates property names and types at registration time to prevent silent errors
- π Toggle between Dark and Light mode with a single call
- π§ Refresh theme for individual controls on demand
- π¦ No dependencies, no DLLs β just drop in and use
Copy ThemeManager.cs into your WinForms project.
First, you must declare the namespace:
using K.ThemeSupport;Then, register controls need to manage:
- Register with multi properties
If the control is already registered, this method overrides its current PropertyMap with a new one
Example:
ThemeManager.Register(label1, new Dictionary<string, (object, object)> {
{"ForeColor", (Color.White, Color.Black)},
{"BackColor", (Color.Black, Color.White)},
{"Font", (new Font("Segoe UI", 12), new Font("Arial", 10))},
{"Text", ("Dark Mode", "Light Mode")}
//...
});- Or you can register with a single property
If the control is already registered, this method add new property to PropertyMap
Example:
ThemeManager.Register(label1, "ForeColor", Color.White, Color.Black);
ThemeManager.Register(label1, "BackColor", Color.Black, Color.White);
ThemeManager.Register(label1, "Font", new Font("Segoe UI", 12), new Font("Arial", 10));
ThemeManager.Register(label1, "Text", "Dark Mode", "Light Mode");
//...The following mode-switching methods are available for use:
- Switches the mode between light and dark:
ThemeManager.ToggleTheme();- Specify the mode explicitly: true β Dark mode, false β Light mode:
ThemeManager.SetTheme(bool darkMode);- Reload current mode for all registered controls:
ThemeManager.Refresh();- Reload current mode for a specific control:
ThemeManager.Refresh(Control control);Unlike skinning frameworks or vendor-specific solutions, ThemeManager gives you:
- Full control over individual properties
- Support for any control type
- No external dependencies
- Easy integration into existing projects
- Requires .NET Framework or .NET Core with WinForms
- Compatible with C# 7.0 and above (no advanced syntax used)
- You can extend it to support more types or persist theme settings
This project is released under the MIT License.
Feel free to use, modify, and share it in your own projects.
If you find this useful, give it a β on GitHub!
Issues, suggestions, or pull requests are welcome.