Jump to content
Ian Branch

Set form height based on resolution??

Recommended Posts

Hi Team,

I have had the practice of making the form large enough during IDE development to place all the non-visual components off to the side or below the visual components during development and setting the form height & width so the Form is the correct height and width.

This has worked well, until now.

In the past my and my users have used 1920 x 1080 screens so everything was fine.

I have just installed a 3940 x 2160 monitor. 🙂  Oh the joy of it all. 🙂

Any way, when I now run the App(s) the various forms are too condensed, covering some of the visible components. 😞

Of course, if I shrink the forms to their desired run-time size and comment out the height/width instructions, all is fine.

So, to my question..  Is there a mechanism to detect the DPI and adjust the Form height accordingly??

something like..  height := ScreenDPI() * iDesiredHeight;

Appreciate any suggestions,

Regards & TIA,

Ian

 

Share this post


Link to post

Which version of Delphi are you using?  Recent versions have better support for DPI.  Have a look at things like the TForm.Monitor.PixelsPerInch property and the TControl.ScaleForPPI() method.

 

Try something like this:

Height := MulDiv(iDesiredHeight, Monitor.PixelsPerInch, 96);

Or this:

Height := iDesiredHeight
ScaleForPPI(Monitor.PixelsPerInch);

I don't know if these are actually correct or not.  I don't design UIs for multi-DPI systems.

Share this post


Link to post

Hi Remy,

Apologies, yes I should have mentioned I am using D10.4.

Thanks you for the suggestions, I shall give them a try.

Regards,

Ian

Share this post


Link to post
59 minutes ago, Remy Lebeau said:

Height := MulDiv(iDesiredHeight, Monitor.PixelsPerInch, 96);

Tks Remy,  this works perfectly on all the different resolutions I have tried.

Regards,

Ian

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

×