Difference between revisions of "DarkMode.cs"
m |
m |
||
| (8 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | == | + | == Dark Mode == |
| − | 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 file 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_Example. | + | ''Example:'' Default Light Mode / Dark Mode<br> |
| + | [[File:DarkMode_Example.png|frameless|1000px|Example: Default Light Mode / Dark Mode]]<br> | ||
== Script == | == Script == | ||
| − | ''' | + | {| class="wikitable" |
| − | + | |- | |
| − | ''' | + | | '''Repository:''' || https://github.com/d-v-d-k/DarkMode.cs |
| + | |- | ||
| + | | '''View/Edit Script:''' || https://github.com/d-v-d-k/DarkMode.cs/blob/main/DarkMode.cs | ||
| + | |- | ||
| + | | '''View Script Raw:''' || https://raw.githubusercontent.com/d-v-d-k/DarkMode.cs/refs/heads/main/DarkMode.cs | ||
| + | |- | ||
| + | | '''Download Last Release:''' || https://github.com/d-v-d-k/DarkMode.cs/releases/latest/download/DarkMode.cs | ||
| + | |} | ||
== Usage == | == Usage == | ||
Add DarkMode.cs to the project solution.<br> | Add DarkMode.cs to the project solution.<br> | ||
| − | [[File:DarkMode Solution.png|frame| | + | [[File:DarkMode Solution.png|frame|626px|left]]<br> |
<br> | <br> | ||
<br> | <br> | ||
| Line 25: | Line 33: | ||
<code>DarkMode.Enable(form);</code><br> | <code>DarkMode.Enable(form);</code><br> | ||
| − | + | Apply Dark Mode style to this Form.<br> | |
''Example:'' On each Form Initialize Event | ''Example:'' On each Form Initialize Event | ||
| Line 41: | Line 49: | ||
DarkMode.Enable(form); | DarkMode.Enable(form); | ||
form.Show(); | form.Show(); | ||
| + | </pre> | ||
| + | |||
| + | ''Example:'' When a Button gets clicked | ||
| + | <pre> | ||
| + | private void buttonDarkMode_Click(object sender, EventArgs e) | ||
| + | { | ||
| + | DarkMode.Enable(this); | ||
| + | } | ||
</pre> | </pre> | ||
=== Inherit=== | === Inherit=== | ||
<code>DarkMode.Inherit(form);</code><br> | <code>DarkMode.Inherit(form);</code><br> | ||
| − | Inherit and apply the current Windows User Dark | + | Inherit and apply the current Windows User Light/Dark Mode preference to this Form.<br> |
| − | + | ||
| + | Can only Inherit on Windows versions that support Dark Mode (Window 10/11), otherwise Inherit will automatically default to standard Light Mode (change this with <code>DarkMode.UserDefault = true;</code>). | ||
=== Disable=== | === Disable=== | ||
<code>DarkMode.Disable(form);</code><br> | <code>DarkMode.Disable(form);</code><br> | ||
| − | Revert this Form back to | + | Revert this Form back to standard 'Light Mode' style defaults.<br> |
| + | |||
| + | == Support == | ||
| + | '''Operating System:''' Windows 98 - Windows 11<br> | ||
| + | '''.NET Version:''' .NET Framework 2.0 - latest (4.8.1)<br> | ||
| + | |||
| + | === Components === | ||
| + | |||
| + | {| class="wikitable sortable" | ||
| + | |- | ||
| + | ! Component !! Notes | ||
| + | |- | ||
| + | | TitleBar || Only for Windows 10 and Windows 11. | ||
| + | |- | ||
| + | | Form || | ||
| + | |- | ||
| + | | '''Control:''' TabControl || Including TabPage controls, and TabPage buttons. | ||
| + | |- | ||
| + | | '''Control:''' Panel || | ||
| + | |- | ||
| + | | '''Control:''' GroupBox || | ||
| + | |- | ||
| + | | '''Control:''' Label || ''* No changes needed.'' | ||
| + | |- | ||
| + | | '''Control:''' LinkLabel || | ||
| + | |- | ||
| + | | '''Control:''' Button || | ||
| + | |- | ||
| + | | '''Control:''' TextBox || | ||
| + | |- | ||
| + | | '''Control:''' MaskedTextBox || | ||
| + | |- | ||
| + | | '''Control:''' RichTextBox || | ||
| + | |- | ||
| + | | '''Control:''' NumericUpDown || | ||
| + | |- | ||
| + | | '''Control:''' ComboBox || | ||
| + | |- | ||
| + | | '''Control:''' ListBox || | ||
| + | |- | ||
| + | | '''Control:''' CheckedListBox || | ||
| + | |- | ||
| + | | '''Control:''' CheckBox || ''* No changes needed.'' | ||
| + | |- | ||
| + | | '''Control:''' RadioButton || ''* No changes needed.'' | ||
| + | |- | ||
| + | | '''Control:''' ListView || | ||
| + | |- | ||
| + | | '''Control:''' TreeView || | ||
| + | |- | ||
| + | | '''Control:''' StatusStrip || | ||
| + | |- | ||
| + | | '''Control:''' MenuStrip || | ||
| + | |- | ||
| + | | '''Control:''' ContextMenuStrip || Including ContextMenuStrips created outside the Form code (Designer). | ||
| + | |- | ||
| + | | '''Control:''' ToolStripItem || Including; ToolStripMenuItem, ToolStripTextBox, ToolStripComboBox, ToolStripSeperator. | ||
| + | |- | ||
| + | | '''Control:''' DataGridView || | ||
| + | |} | ||
Latest revision as of 18:09, 11 May 2026
Dark Mode
A C# Class file 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 / Dark Mode
![]()
Script
| Repository: | https://github.com/d-v-d-k/DarkMode.cs |
| View/Edit Script: | https://github.com/d-v-d-k/DarkMode.cs/blob/main/DarkMode.cs |
| View Script Raw: | https://raw.githubusercontent.com/d-v-d-k/DarkMode.cs/refs/heads/main/DarkMode.cs |
| Download Last Release: | https://github.com/d-v-d-k/DarkMode.cs/releases/latest/download/DarkMode.cs |
Usage
Add DarkMode.cs to the project solution.
Enable
DarkMode.Enable(form);
Apply Dark Mode style to 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();
Example: When a Button gets clicked
private void buttonDarkMode_Click(object sender, EventArgs e)
{
DarkMode.Enable(this);
}
Inherit
DarkMode.Inherit(form);
Inherit and apply the current Windows User Light/Dark Mode preference to this Form.
Can only Inherit on Windows versions that support Dark Mode (Window 10/11), otherwise Inherit will automatically default to standard Light Mode (change this with DarkMode.UserDefault = true;).
Disable
DarkMode.Disable(form);
Revert this Form back to standard 'Light Mode' style defaults.
Support
Operating System: Windows 98 - Windows 11
.NET Version: .NET Framework 2.0 - latest (4.8.1)
Components
| Component | Notes |
|---|---|
| TitleBar | Only for Windows 10 and Windows 11. |
| Form | |
| Control: TabControl | Including TabPage controls, and TabPage buttons. |
| Control: Panel | |
| Control: GroupBox | |
| Control: Label | * No changes needed. |
| Control: LinkLabel | |
| Control: Button | |
| Control: TextBox | |
| Control: MaskedTextBox | |
| Control: RichTextBox | |
| Control: NumericUpDown | |
| Control: ComboBox | |
| Control: ListBox | |
| Control: CheckedListBox | |
| Control: CheckBox | * No changes needed. |
| Control: RadioButton | * No changes needed. |
| Control: ListView | |
| Control: TreeView | |
| Control: StatusStrip | |
| Control: MenuStrip | |
| Control: ContextMenuStrip | Including ContextMenuStrips created outside the Form code (Designer). |
| Control: ToolStripItem | Including; ToolStripMenuItem, ToolStripTextBox, ToolStripComboBox, ToolStripSeperator. |
| Control: DataGridView |
