Skip to content

Marcello-Goncalves/DarkModeForm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💡 DarkModeForm

This is a Simple Exemple of how a Dark Mode Can be Implemented to a Desktop Program Created With Microsoft's WinForms Using the DotNet Framework 4.8.1 and the C# Programming Language.


The Program Consists of a Simple Form with 3 RadioButton Controls:

  • Light  - Applies Windows' Light Theme's BackColor And ForeColor (#FFFFFF & #000000 Respectively).
  • Dark  - Applies Windows' Dark Theme's BackColor And ForeColor (#202020 & #FFFFFF Respectively). But Also Calls The UseImmersiveDarkMode( ) Method From The DarkTitleBar Class (More on it Below).
  • System - Calls The Status( ) Method From the SystemTheme Class in order to Identify the OS's Use of a Light or Dark Theme.

Light Dark


The DarkTitleBar Class

The DarkTitleBar Class Applies a Black Color (#000000) To the TitleBar (e.g. the Dark Mode of Apps like PowerShell or PowerToys).

The Credit of This Class' Code Development Goes to Jonas Kohl as Displayed on his Answer to This Thread on StackOverflow and can be Further Observed on His DarkModeEnabler Repository.

But also To Jonas for Adapting it to a Class and Reinforcing the Need For an AppManifest to be Added To The Solution and The Line of Code Referring to the Operating System (in This Repo's Case Windows 10 and 11) to be Uncommented.

This is Being Targeted to Windows 10 and Newer Systems Since Older Versions Are No Longer Maintained.


The SystemTheme Class

The SystemTheme class Retrives The AppsUseLightTheme DWORD From The Registry in order to Detect the OS's Current Theme and Apply The Respective Changes to The Application´s Form.

This Class Must Be Also Credited To Another Fellow Developer, Rena821 as seen in His Answer to This Thread on StackOverflow.


Credits

Besides The Due Accreditation to Jonas Kohl, Jonas and Rena821's Work, I also Used A Modified Version of This Icon Designed by Freepik Company, S.L from Flaticon as the Main Icon of the Application.

Bulb


Closing Thoughts

This is Obviously not an Elaborate Application but rather a Simple Implementation of a Feature that is Common and Convenient on more Modern/Complex UI Frameworks, Applied to Windows Forms.

This Repo is intended To make it Easier and Clearer to apply this feature in Other WinForms Projects and Serve As Documentation.