Skip to content
Detecting and acting on Windows' Dark Mode theme setting using Delphi
Pascal
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitattributes
.gitignore
LICENSE
README.md
Unit1.dfm
Unit1.pas
WindowsDarkMode.pas
sunnies.ico
sunnies_16.png
sunnies_32.png
vcltips1.dpr
vcltips1.dproj
vcltips1.res

README.md

DelphiDarkMode

Detecting and acting on Windows' Dark Mode theme setting in Delphi

Originally written by Ian Barker

There is a blog post describing this code and the reasoning behind it here: https://www.codedotshow.com/blog/coderage-2019-vcl-the-dark-side/

Free software - use for any purpose including commercial use.

Functions


function DarkModeIsEnabled: boolean; Checks the Windows registry to see if Windows Dark Mode is enabled


procedure SetAppropriateThemeMode(const DarkModeThemeName, LightModeThemeName: string);

Automatically sets a Dark Mode theme if Windows is running in Dark Mode To use:

  1. Got to project properties
  2. Select appearance and choose two or more themes. Note down the names!
  3. In your FormCreate (or wherever) put the following line: SetAppropriateThemeMode(**name_of_the_dark_theme**, **name_of_the_non_dark_theme**);

For example:

SetAppropriateThemeMode('Carbon', 'Windows10');


procedure SetSpecificThemeMode(const AsDarkMode: Boolean; const DarkModeThemeName, LightModeThemeName: string);

Sets either a Dark Mode or non Dark mode theme based in the "AsDarkMode" boolean For example:

SetSpecificThemeMode(False, 'TheDarkModeThemeName', 'TheLightModeThemeName');

Would change the application theme to the theme with the name 'TheLightModeThemeName' if it exists.

End of document

You can’t perform that action at this time.