Chau Chee Yang
Chau Chee Yang

Reputation: 19620

Runtime created TButton control on High DPI aware application doesn't scale to monitor's DPI

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?

Upvotes: 0

Views: 668

Answers (1)

David Heffernan
David Heffernan

Reputation: 612954

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.

Upvotes: 3

Related Questions