Difference between revisions of "DarkMode.cs"

From DanIT
Jump to navigation Jump to search
m
m
Line 1: Line 1:
== General ==
+
== Class ==
 
A C# Class for .NET Framework 2.0 - 4.8.1 (Windows 98 - Windows 11) to enable Dark Mode on Windows Forms.<br>
 
A C# Class for .NET Framework 2.0 - 4.8.1 (Windows 98 - Windows 11) to enable Dark Mode on Windows Forms.<br>
  
 
By default only .NET 9.0 (no Framework) and higher supports Dark Mode natively, which is an optional download for Windows 10/11 only.<br>
 
By default only .NET 9.0 (no Framework) and higher supports Dark Mode natively, which is an optional download for Windows 10/11 only.<br>
  
[[File:DarkMode_Light.png|frameless|360px|Example: Default Light Mode]] [[File:DarkMode_Dark.png|frameless|360px|Example: Dark Mode Enabled]]<br>
+
[[File:DarkMode_Light.png|frameless|491px|Example: Default Light Mode]] [[File:DarkMode_Dark.png|frameless|491px|Example: Dark Mode Enabled]]<br>
  
 
== Script ==
 
== Script ==
Line 11: Line 11:
  
 
== Usage ==
 
== Usage ==
[[File:DarkMode Solution.png|thumb]]
+
[[File:DarkMode Solution.png|frame|224px|right]]
 
Add DarkMode.cs to the project solution.<br>
 
Add DarkMode.cs to the project solution.<br>
  

Revision as of 07:15, 25 April 2026

Class

A C# Class for .NET Framework 2.0 - 4.8.1 (Windows 98 - Windows 11) to enable Dark Mode on Windows Forms.

By default only .NET 9.0 (no Framework) and higher supports Dark Mode natively, which is an optional download for Windows 10/11 only.

Example: Default Light Mode Example: Dark Mode Enabled

Script

Download: DarkMode.cs
GitHub: https://github.com/d-v-d-k/DarkMode.cs

Usage

DarkMode Solution.png

Add DarkMode.cs to the project solution.

Enable

DarkMode.Enable(this);

Enable Dark Mode style on this Form.

Example: On each Form Initialize Event

public Form1()
{
    InitializeComponent();
    DarkMode.Enable(this);
}

Example: When creating a Form instance

Form1 form = new Form1();
DarkMode.Enable(form);
form.Show();

Inherit

DarkMode.Inherit(this);

Inherit and apply the current Windows User Dark/Light Mode preference to this Form.
Only works in Windows 10/11, otherwise Inherit will automatically default to standard Light Mode (change with DarkMode.UserDefault).

Disable

DarkMode.Disable(this);

Revert this Form back to default Light Mode style.