Jump to content
Angus Robertson

High DPI Scaling

Recommended Posts

I design forms on a 4K monitor running at 120 dpi, but have a second side monitor that runs at 96 dpi, so no scaling. 

 

My forms all store their screen position and size. 

 

If I move a form onto the side monitor, close and re-open it, Form.PixelsPerInch seems to be that of the primary monitor, not the side monitor, so the form gets smaller in size, because the wrong scaling was saved.  

 

Is there a way to persuade Delphi to scale the form according to the monitor on which it is opened, rather than the primary monitor?

 

Angus

 

 

Share this post


Link to post
Just now, Angus Robertson said:

Is there a way to persuade Delphi to scale the form according to the monitor on which it is opened, rather than the primary monitor?

This is already how the RTL works.

 

I imagine there's a logic error somewhere in your code. Maybe in the code that persists position/size. Or perhaps something else.

Share this post


Link to post

I don't have any scaling or screen code, I just save HWTL.   

 

When opened on the 96dpi monitor, Screen.PixelsPerInch says 120 not 96, so I don't believe the correct monitor is being set when I change Width to move it to the other monitor.  Or am I supposed to rescale the form myself at that point?  

 

Angus

 

 

  

Share this post


Link to post

But fwiw when i persist window location I also persist the dpi of the monitor where the window was located so that when it's time to restore size and position this can be done even if the window is on a different monitor or the dpi of the monitors has changed. 

 

Perhaps this is your issue. Perhaps not. With no detail all we can do is guess. 

 

It should be simple to make a trivial do nothing example to demonstrate. 

Share this post


Link to post
13 hours ago, Angus Robertson said:

I don't have any scaling or screen code, I just save HWTL.   

 

When opened on the 96dpi monitor, Screen.PixelsPerInch says 120 not 96, so I don't believe the correct monitor is being set when I change Width to move it to the other monitor.  Or am I supposed to rescale the form myself at that point?  

I found the VCL's built in scaling lacking a lot on systems with monitors with different scale factors. My "solution" was to do the scaling myself, which turned into a nightmare, because it means fighting the VCL's built in code. Especially when the code that works perfectly in mixed scaling then falls flat on High DPI only settings, so I have to test in many different configurations which consumes time to no end.

 

Sometimes I wish I had never bought a High DPI monitor. Life was much simpler back then. 😉

 

(Sorry to be unhelpful, I just wanted to tell you that you are not alone in experiencing these problems.)

Share this post


Link to post

The program in question is an ICS sample, https://svn.overbyte.be/svn/icsv9/demos-delphi-extra/IcsAppMonMan1.pas  It's a Websocket monitoring application.  

 

It saves the form position and size in the same way as 50 other ICS samples have for 25 years, nothing clever.  But it does not work with Delphi 11 on the secondary monitor with a different DPI to the primary. 

 

Since the design DPI and monitor DPI are the same, there should be no scaling, that is the issue.  But Delphi thinks it's on the wrong monitor.  

 

I'm not going to update 50 samples for this rare situation, but this particular ICS sample stays open on my side screen 24/7, only stopping for reboots, after which I have to resize it, annoyingly. 

 

Angus

 

 

Share this post


Link to post

I can understand why you don't want to change all those apps - but did you try the settings to see if they have the desired effect?

Share this post


Link to post
1 hour ago, dummzeuch said:

I found the VCL's built in scaling lacking a lot on systems with monitors with different scale factors. My "solution" was to do the scaling myself, which turned into a nightmare, because it means fighting the VCL's built in code. Especially when the code that works perfectly in mixed scaling then falls flat on High DPI only settings, so I have to test in many different configurations which consumes time to no end.

As a counter-point to this, I'm using 11.3 and have been largely very satisfied with how the VCL handles per monitor and high DPI scaling. So I'm confident that it is possible to get this right.

Share this post


Link to post

Seems there are several form methods and properties I need to use to fix my problem, like ScaleForCurrentDPI, OnAfterMonitorDPIChanges, etc, so need to do a little more testing.

 

Angus

 

 

Share this post


Link to post

Think I've fixed my scaling problem, by simply re-arranging the order in which the INI settings are read to change the form position and size.  

 

Setting Left causes a rescaling of the form if the monitor DPI changes, so if Width has been set for the new size before it scales, but if Width is set afterwards it does not change.  

 

Needed a lot of logging to see the order in which Delphi does the scaling. 

 

Angus

 

  • Thanks 2

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×