High DPI form design - Resizing automatically

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
JeffreyN
Posts: 4
Last visit: Tue Jul 12, 2022 12:05 am

High DPI form design - Resizing automatically

Post by JeffreyN »

Hi All
For the last while, I've been working on fixing one of my GUIs developed in Powershell Studio to allow it to display correctly on high DPI screens. (It turns out my original design was NOT very high DPI friendly). With the assistance of https://info.sapien.com/index.php/guis/ ... i-displays, it's looking much better, but I still have some questions.

Firstly, the article mentions the SetDPIAwareness snippet.. Where does that go, and is it still needed?

Secondly, Layout issues are being resolved by TableLayoutPanels, and docking. I'll then scale the tablelayoutpanel using a small loop within the form_load, eg:
  1. $colCount = $tablelayoutpanel1.ColumnCount
  2. for ($col = 0; $col -lt $colCount; $col++){
  3.   $tablelayoutpanel1.ColumnStyles[$col].Width = ConvertTo-ScaledPixel -Form $form1 -Width $tablelayoutpanel1.ColumnStyles[$col].Width
  4. }
(Repeat for rows as well)

The problem then is that the contents of the cells do not also scale. Labels look like they do scale up, but not text boxes or other object types. From the article, it looked like text boxes should scale, as long as the font is set.

Is there a way to automatically scale these elements?
Or do I just need to set the scaling on everything?

If someone does have a sample of an application with various elements (text boxes, labels, tabs) etc, that they are willing to share, it would be appreciated.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: High DPI form design - Resizing automatically

Post by jvierra »

My first thought is that the TableLayoutPanel is not a display control. It is a container control that auto scales to the contents of the cells.
User avatar
JeffreyN
Posts: 4
Last visit: Tue Jul 12, 2022 12:05 am

Re: High DPI form design - Resizing automatically

Post by JeffreyN »

Thanks jvierra.
I know I am doing something wrong, but have no idea what. (Scaling is doing very odd things).

Does anyone know of a sample high dpi compatible design that I could take a look at? I did look around, but have not found anything as of yet.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: High DPI form design - Resizing automatically

Post by jvierra »

The following article will help you understand what the issues are and how you can adjust for the type of scaling you wish to use.
https://info.sapien.com/index.php/guis/ ... i-displays

The bottom line is that WinForms was never designed to use high DPI monitors and the forms layout and rendering methods create conflicts that must be resolved with deign time choices. There is no "one size fits all" here.

I cannot give you any examples as al of my systems and client systems restrict h DPI settings on monitors due to the use of many legacy apps that will not work on a high DPI monitor. Slowly we are upgrading the apps and, in some cases apps have been isolated to a VM that can resolves this. Still, high DPI makes many GUI apps unusable or difficult to use due to scaling issues. Old VB6 apps end up on the screen as postage stamps. Not very useful.

The best forms tool to use for high DPI is WPF as it is much more compatible do to its "flow" model.

Sapien recommends using layout panels as these are dynamically arranged and maintain control positions and size relations more accurately. Also if setting "font" mode then you must manually set all controls font property or inheritance will fail.

In the end it is your job to work out how to correctly design your form so that it behaves the way you need.
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked