Many times we need to override windows default settings or customize our application by code, irrespective of user settings in windows for better user experience. Your application has been built with options to apply certain themes and the user also has the flexibility to change Windows themes for entire windows/apps. In this case, your application user experience should not be affected by user system settings. This post can guide you to set the themes in your Windows VCL application.

How to check whether dark mode is enabled?

  • Press Windows + R -> Type Regedit cmd in Run Command window.
  • Navigate to the folder: Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize.
  • Check AppsUseLightTheme Keyword and if its value is 1 then the windows apps theme is in Light mode and 0 means it’s in Dark mode.

How to set the themes in Delphi from project options :

In Delphi IDE, Go to -> Project Menu -> options -> appearance -> Select the available themes suitable for your application. Carbon for Dark theme for example.

You application theme settings:

If you want to give a better user experience explicitly irrespective of (or) according to windows themes selected by the user in the machine, first programmatically check the app theme mode. Navigate to the following location Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize and get the keyword AppsUseLightTheme value. Accordingly build your logic of setting the VCL theme using the VCL API to set the themes.

Note: Platform specific conditional defines need to be included accordingly if it is cross platform application.

Check the below Video for the full demonstration of setting the dark/light theme Vice-versa for a VCL application.

Check out the latest Delphi 10.4.1 which supports High DPI Styles and VCL per control styling for your applications.

The post Easily Customize Your Delphi VCL Application With Dark And Light Themes According to Windows Mode first appeared on Embarcadero Blogs.