Difference between revisions of "DarkMode.cs"

From DanIT
Jump to navigation Jump to search
m
Line 22: Line 22:
 
Enable Dark Mode style on this Form.<br><br>
 
Enable Dark Mode style on this Form.<br><br>
  
Example: On each Form Load Event
+
Example: On each Form Initialize Event
 
<pre>
 
<pre>
private void Form1_Load(object sender, EventArgs e)
+
public Form1()
 
{
 
{
 +
    InitializeComponent();
 
     DarkMode.Enable(this);
 
     DarkMode.Enable(this);
 
}
 
}

Revision as of 02:13, 25 April 2026

General

C# Class for .NET Framework 2.0 - 4.8.1 (latest) to enable Dark Mode on Forms.
By default only .NET 9.0 and higher supports Dark Mode natively, which is an optional download for Windows 10/11.





Script

Download: Download Script

Preview Script

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.

Disable

DarkMode.Disable(this);

Revert this Form back to default Light Mode style.