Skip to content

KhoaDo472005/WinForms-ThemeManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 

Repository files navigation

ThemeManager for WinForms

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.


✨ Features

  • βœ… 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

πŸš€ Getting Started

1. Add the file

Copy ThemeManager.cs into your WinForms project.

2. Register controls with theme-specific properties

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");
//...

3. Call methods to toggle theme

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);

🧠 Why this over other libraries?

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

πŸ“Œ Notes

  • 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

πŸ“‚ License

This project is released under the MIT License.
Feel free to use, modify, and share it in your own projects.


πŸ’¬ Feedback & Contributions

If you find this useful, give it a ⭐ on GitHub!
Issues, suggestions, or pull requests are welcome.