0
votes

I am using High DPI option in Delphi 10 Seattle project. The controls (buttons, labels, check box) on forms scale well on different DPI setting. These controls were drop to form at design time.

However, I have some TButton control that I created at runtime. These runtime created button doesn't scale and honour the monitor's DPI setting. For example, a design time TButton with height of 25 at design time scale to 31. But the runtime created TButton control doesn't scale from 25 to 31.

I may do extra calculate on the left, top, width and height on runtime created TButton control but that would be tedious. Is there any ready solution available in Delphi that allow us to scale according to monitor's DPI?

1

1 Answers

3
votes

You need to perform this scaling in your code. The VCL does not attempt to perform any such scaling for controls created manually at runtime.

You can use the protected ChangeScale method of TControl to perform the scaling. This accepts two parameters, M and D, the numerator and denominator respectively. Pass Form.PixelsPerInch for M and 96 for D.