Difference between revisions of "DarkMode.cs"

From DanIT
Jump to navigation Jump to search
(Created page with "thumb|right C# Class for .NET Framework 2.0 - 4.8.1 (latest) to enable Dark Mode on Forms.<br> By default only .NET 9.0 and higher supports Dark Mode nati...")
 
Line 1: Line 1:
[[File:Example.png|thumb|right]]
+
== General ==
 
C# Class for .NET Framework 2.0 - 4.8.1 (latest) to enable Dark Mode on Forms.<br>
 
C# Class for .NET Framework 2.0 - 4.8.1 (latest) to enable Dark Mode on Forms.<br>
 
By default only .NET 9.0 and higher supports Dark Mode natively, which is an optional download for Windows 10/11.<br>
 
By default only .NET 9.0 and higher supports Dark Mode natively, which is an optional download for Windows 10/11.<br>
 +
[[File:Example.png|thumb|left]]
 +
<br>
 +
<br>
 +
<br>
 +
<br>
  
 
== Script ==
 
== Script ==
[[Media:DarkMode.cs|Download DarkMode.cs]]
+
'''Download:''' [[File:DarkMode.cs|Download Script]]<br>
<pre>
+
 
test
+
[[Media:DarkMode.cs|Preview Script]]<br>
</pre>
 
  
 
== Usage ==
 
== Usage ==
 +
[[File:DarkMode Solution.png|thumb]]
 +
Add DarkMode.cs to the project solution.<br>
  
 
=== Enable ===
 
=== Enable ===
 
<code>DarkMode.Enable(this);</code><br>
 
<code>DarkMode.Enable(this);</code><br>
  
Enable Dark Mode style on this Form.<br>
+
Enable Dark Mode style on this Form.<br><br>
  
On each Form Load Event, simply add the following line to enable Dark Mode, example:<br>
+
Example: On each Form Load Event
 
<pre>
 
<pre>
 
private void Form1_Load(object sender, EventArgs e)
 
private void Form1_Load(object sender, EventArgs e)
Line 24: Line 30:
 
</pre>
 
</pre>
  
Example:
+
Example: When creating a Form instance
 
<pre>
 
<pre>
 
Form1 form = new Form1();
 
Form1 form = new Form1();
Line 33: Line 39:
 
<code>DarkMode.Inherit(this);</code><br>
 
<code>DarkMode.Inherit(this);</code><br>
  
Inherit and apply the current Windows User Dark/Light Mode to this Form.<br>
+
Inherit and apply the current Windows User Dark/Light Mode preference to this Form.<br>
  
 
=== Disable===
 
=== Disable===

Revision as of 01:02, 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 Load Event

private void Form1_Load(object sender, EventArgs e)
{
    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.