

Woohoo! After a few weeks of struggle I’ve finally high-dpi enabled my used-across-the-globe Delphi application.

It was not a too hard job – it just took a lot of time and experimenting (read: fixing) how the UI of the application appears on various 4K displays having various settings for “Make text and other items larger or smaller” (Windows Vista/7/8), which is the same as “Set a custom scaling level” (Windows 10).

Actually, saying that “high-dpi enabling” took a few weeks is wrong. There are really just a few things that need to be done in your Delphi application to make it properly DPI aware. Alas, what takes time are those few (third party AND VCL) controls that refused to be properly scaled so you really have to test on various screen sizes and various DPI levels.

If you do not know what I’m talking about then you are kind of blessed.

But, sooner or later you will find yourself searching the Internet for keywords including: Delphi, 4K displays, high DPI, form / control scaling / sizing, DPI awareness, PixelsPerInch, DPI virtualization in Windows and alike.

The thing is that today’s laptops and desktops come standardly with (very) high resolution screens. If you think Full HD (1920 x 1080) is big, what do you then think of 3480 x 2160 pixels? What’s worst is that those high resolutions tend to be used on small laptops (e.g. 15’’ diagonal). Just imagine a standard glyph of 16×16 pixels on your standard TBitBtn. That’s supper small and not usable! This is the reason why Windows turns on DPI scaling by default so stuff on such screens becomes bigger (except your 16×16 px glyph on that button which remains 16×16 px and is barely visible, ha!). And this is where the problems start! Your Delphi applications will probably look super (small or stretched) ugly if the application is not DPI aware or will look messed up if the controls you use do not know how to scale themselves (and the application is DPI aware). Not to mention you can have more screens attached to your computer and each screen having different resolution and more importantly different scaling factor.

Now, I want this post to be more of a collection of guidelines for (myself and) those just starting to fight the high DPI battle. As when I started I really had to read a lot and make sure I understand what’s happening and what should be best done.

So, here’s the list of must-reads you want to go through to understand why your super nice Delphi application appears so ugly or so small on your friends laptop:

Writing DPI-Aware Desktop and Win32 Applications

This is where you start to get the idea what’s happening. Notes on High DPI features in Windows. DPI Virtualization and scaling. Differences between non-DPI aware application, DPI aware applications and per monitor-DPI aware applications. This is not directly Delphi related – rather Windows related – but this is where you start.

How-To Guide: Upgrading Your Delphi VCL Applications To Support 4K Displays

Now we talk Delphi. Also repeat what is stated in the first article but from the perspective of a Delphi developer.

New per-DPI awareness in VCL applications

RAD Studio 10 Seattle is the first RAD Studio to easily let you say your application IS DPI aware.

How do I make my GUI behave well when Windows font scaling is greater than 100%

A great discussion on StackOverflow talking about high-DPI enabling Delphi application before Delphi 10.Seattle. Plus: how to manually scale in code.

I guess you will end up reading more high-dpi articles than those listed above – but this gives you a nice “where to start from” guide.

To conclude, this is what I did for my Delphi application (and that actually, and as I said, didn’t take too long):

High-DPI enable the application using a manifest Make sure all forms have their Scaled property set to true Use MulDiv(some_value_when_on_96, Screen.PixelsPerInch, 96) when needed (setting sizes and coordinates from code for example)

What did took a lot of time and energy was: fix lots of cases where (some) controls refused to get properly scaled!

For example, this is how the TColorBox displays on 250% (default for 3480 x 2160 @ 15”):

In the next posts I’m sharing some high-dpi solutions (and compromises) I used: Delphi High-DPI Road: Ensuring Your UI Looks Correctly for TImage, TColorBox, Owner Drawn TComboBox , TStatusBar and some more.