AlexV
AlexV

Reputation: 23088

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.

Upvotes: 0

Views: 541

Answers (3)

dummzeuch
dummzeuch

Reputation: 11217

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;

Upvotes: 0

dwrbudr
dwrbudr

Reputation: 817

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

Upvotes: 0

HeartWare
HeartWare

Reputation: 8243

Button1.Height:=Edit1.Height;
Button1.Top:=Edit1.Top;

in either FormCreate, FormActivate or FormResize.

(provided they are both children of the same parent)

Upvotes: 1

Related Questions