Siticone ThemeTracker
The SiticoneThemeTracker is a non-visual component that bridges the gap between your Windows Forms application and the operating system's visual settings.
It silently monitors the Windows Registry and System Messages to detect real-time changes to the System Theme (Light/Dark), Accent Color, and High Contrast mode, allowing your app to adapt instantly.
Configuration
Properties for setting up automatic theme application and targeting specific forms.
| Property | Type | Description & Usage Example |
|---|---|---|
AutoApplyTheme |
bool |
tracker.AutoApplyTheme = true;
If true, the component automatically iterates through controls on the TargetForm and applies basic Light/Dark styling when the system theme changes.
|
TargetForm |
Form | tracker.TargetForm = this; The main form that the tracker should monitor or modify. If AutoApplyTheme is enabled, this form's controls will be styled. |
System State (Read-Only)
Properties exposing the current operating system visual configuration.
| Property | Type | Description |
|---|---|---|
CurrentTheme |
SystemTheme |
var theme = tracker.CurrentTheme;
Returns SystemTheme.Light or SystemTheme.Dark based on Windows 10/11 personalization settings.
|
AccentColor |
Color | Color c = tracker.AccentColor; Returns the active Windows Accent Color (e.g., the color used in the Start Menu or title bars). |
Events
Events triggered when system settings change, allowing for custom handling logic.
// Fired when the user switches between Light and Dark mode in Windows Settings.
tracker.ThemeChanged += (sender, e) =>
{
if (e.NewTheme == SystemTheme.Dark)
{
ApplyDarkMode();
}
else
{
ApplyLightMode();
}
};
// Fired when the user changes their Windows accent color.
tracker.AccentColorChanged += (sender, e) =>
{
// Sync a button's background with the system accent
submitButton.BackColor = e.NewColor;
};
// Fired when Windows High Contrast accessibility mode is toggled.
tracker.HighContrastChanged += (sender, e) =>
{
if (e.IsHighContrast)
{
DisableCustomGradients();
}
};
Methods
Helper methods for manually applying themes to specific controls or forms.
| Method | Description |
|---|---|
ApplyThemeToForm(Form form) |
Recursively iterates through all controls on the specified form and applies specific background/foreground colors based on the `CurrentTheme`. |
ApplyThemeToControl(Control c) |
Applies the current theme logic to a single control and its children. It handles specific types like DataGridView, TextBox, and Button uniquely. |
Detailed Usage Examples
Example 1: Basic Auto-Apply Integration
The simplest way to use the tracker. Just drop it onto your form and configure it in the constructor. The component handles the rest.
public MainForm()
{
InitializeComponent();
// 1. Assign the form to be tracked
siticoneThemeTracker1.TargetForm = this;
// 2. Enable automatic styling
// This will immediately color the form based on current settings
// and listen for future changes.
siticoneThemeTracker1.AutoApplyTheme = true;
}
Example 2: Custom Theme Logic
If you have complex UI elements (like custom painted controls or charts), you should handle the ThemeChanged event manually instead of relying on AutoApplyTheme.
private void SiticoneThemeTracker1_ThemeChanged(object sender, ThemeChangedEventArgs e)
{
if (e.NewTheme == SystemTheme.Dark)
{
// Custom Dark Theme Logic
customChart.BackColor = Color.FromArgb(30, 30, 30);
customChart.AxisColor = Color.Gray;
customChart.LineColor = siticoneThemeTracker1.AccentColor; // Use system accent
lblStatus.ForeColor = Color.WhiteSmoke;
}
else
{
// Custom Light Theme Logic
customChart.BackColor = Color.White;
customChart.AxisColor = Color.Black;
customChart.LineColor = Color.Blue;
lblStatus.ForeColor = Color.Black;
}
}
Example 3: Syncing Accent Color
This example shows how to keep a specific UI element (like a header panel) synchronized with the user's Windows Accent Color preference.
private void Form1_Load(object sender, EventArgs e)
{
// Apply initial color on load
pnlHeader.BackColor = siticoneThemeTracker1.AccentColor;
}
private void SiticoneThemeTracker1_AccentColorChanged(object sender, AccentColorChangedEventArgs e)
{
// Update dynamically when user changes personalization settings
pnlHeader.BackColor = e.NewColor;
// Optional: Adjust text color based on brightness for readability
float brightness = e.NewColor.GetBrightness();
lblTitle.ForeColor = brightness > 0.5f ? Color.Black : Color.White;
}