0

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.

AlexV
  • 22,658
  • 18
  • 85
  • 122

3 Answers3

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

in either FormCreate, FormActivate or FormResize.

(provided they are both children of the same parent)

HeartWare
  • 7,464
  • 2
  • 26
  • 30
  • Wow, I feel dumb to not have tried this before posting my question :P At design time Button1.Height = Edit1.Height and Button1.Top = Edit1.Top (they have the same parent) but not at runtime after the rescale (if under high DPI). I wonder why? VCL bug?? – AlexV Jan 24 '22 at 13:57
  • @AlexV: It depends on your definition of "Bug". There are various ways to scale a component. A TEditBox is perhaps scaled using the Font and then the size of surrounding box follows, whereas the TButton may be scaled based on its current size, and then the font is adjusted to match. That (or some other difference) may lead to a small discrepancy. It's not an exact science :-). – HeartWare Jan 26 '22 at 09:19
  • Yeah I guess you are right :) – AlexV Jan 26 '22 at 13:21
0

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

dwrbudr
  • 607
  • 4
  • 8
0

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;

dummzeuch
  • 10,975
  • 4
  • 51
  • 158