'How to adjust visual components that don't scale correctly in a high DPI aware Windows application made in Delphi?

In a previous question I managed to adjust the "padding" between components using Monitor.PixelsPerInch.

Now I have a different problem: I have a "..." (browse) TButton at the left of a TEdit (path). At design time both VCL components have the same height in their Height property and visually. At runtime under a 4K monitor (scaling of 120%) the components are scaled differently and the TButton have like 3 pixels more at the bottom vs the TEdit which gives an inconsistent GUI.

How can I adjust the height after the automatic (magic) scaling happened? I'm still using Delphi 10.4.



Solution 1:[1]

Use TRelativePanel as a container of both TEdit and TButton. Set TButton properties AlignTopWith, AlignBottomWith, RightOf to the TEdit instance. Also set AlignWithMargins to True and adjust the Margins

Solution 2:[2]

Asuming we are talking about a VCL application: A form has an event OnBeforeMonitorDpiChanged and OnAfterMonitorDpiChanged. In this event you can adjust whatever you like.

Alternatively you can override the form's message handler for WM_DPICHANGED:

procedure WMDpiChanged(var _Msg: TWMDpi); message WM_DPICHANGED;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dwrbudr
Solution 2 dummzeuch