High DPI question

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 1 year and 3 weeks 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
Lembasts
Posts: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

High DPI question

Post by Lembasts »

Im going through https://info.sapien.com/index.php/guis/ ... i-displays.
It mentions that for all controls, the minimum and maximum size needs to be scaled.
Does this apply if all my controls have zero for both minimum and maximum size?
The convert-toscaledpixel function only needs to be set for Listview, splitcontainer and treeview controls?
User avatar
Lembasts
Posts: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Re: High DPI question

Post by Lembasts »

I have worked through all the modifications as recommended and I have run into a problem.
I have a project with about 24 different forms. Some of the forms resized fine and some didnt when I changed the monitor scale.
What I noticed was that for the forms that resized correctly , the font property on the form control itself was set to default i.e. Microsoft Sans Serif, 8.25pt.
So I modified one of the forms that didnt resize properly that had a different font setting on the Form control back to the default.
I can see that it worked as the font property for that form is not bolded.
All the controls within that form, as recommended, have manual font settings e.g. labels and textboxes etc.
My issue is that it still does not resize properly. The controls are running into each other and the text size didnt change.
Any ideas?
User avatar
Lembasts
Posts: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Re: High DPI question

Post by Lembasts »

I fixed the above problem!
What I did was to 'pretend' to change the font properties for all controls on the form.
i.e. I selected the controls and opened the font dialogue and changed the font style from regular to bold and then back to regular.
User avatar
Lembasts
Posts: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Re: High DPI question

Post by Lembasts »

Thanks for that article. For a long time I put my apps in the 'high dpi' too hard basket.
Following the article along with the 'pretend' font changes has worked a treat.
There was one thing that I was wondering about.
When I change the size in the display settings to %200, the fonts are resized accordingly but look a bit fuzzy. I noticed that one of the Window pop dialogue boxes had fonts resized that were smooth.
Its as though the latter popup was using a different font rendering technique.
Is it possible to do that with my PS studio apps? i.e. using a specific font that resizes smoothly?
User avatar
Lembasts
Posts: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Re: High DPI question

Post by Lembasts »

Continuing with my scaling saga. Came across a new one today.
When I was trying to do the scaling using the column.width, it was working fine until....

I had a form with a list view and only one column. When changing the monitor scale to 200% it was reporting the column.width property as zero. At 100% the column.width reported fine.
The workaround was to add another column with a width of one and that fixed it.
User avatar
Lembasts
Posts: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Re: High DPI question

Post by Lembasts »

Lembasts wrote: Mon Feb 20, 2023 7:13 pm Continuing with my scaling saga. Came across a new one today.
When I was trying to do the scaling using the column.width, it was working fine until....

I had a form with a list view and only one column. When changing the monitor scale to 200% it was reporting the column.width property as zero. At 100% the column.width reported fine.
The workaround was to add another column with a width of one and that fixed it.
So the above fix worked but I dont have all the screen resolutions to test.
Turns out that for a resolution of 3840 X 2160 at 150%, the column width is reporting as zero for some but not all listviews. If I set the size to 100%, column width is reporting correctly.
I use the following function for all my listviews:

Code: Select all

function Set-LVColumnScale ($listview)
{
	foreach ($column in $listview.columns)
	{
		$column.width = ConvertTo-ScaledPixel -Form $global:CurrentForm -Width $column.width
	}
}
Its the $column.width that is reporting as zero.
But not for all list views and not for the vast majority of resolutions.
All the form controls that have listviews have their font all set to the default - Microsoft sans serif 8.25.
Every listview has specifically been set a different font (verdana 8.25).
All the listviews, working and not, have preset column collections with preset column widths i.e. no dynamically created columns.
In looking at all the listviews, working or not, there doesnt seem to be a specific property that is different between working and not working listviews.
I have to find a fix though....
User avatar
Lembasts
Posts: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Re: High DPI question

Post by Lembasts »

So I exported the code and saw that for both the listviews that worked and the listviews that didnt work that the columns were added to the controls with the appropriate width property set.
So I tried this for one of the listviews that didnt work.
I deleted the manually added column in the PS IDE and ran this line of code at the very beginning of the form load event:
[void]$listviewMembers.Columns.Add('Members', 'Group Members',500)
and guess what - it worked! The column width was reported correctly.
Now why this is happening is another matter but at least I have a workaround.
User avatar
Lembasts
Posts: 405
Last visit: Wed Mar 20, 2024 1:40 pm
Has voted: 1 time
Been upvoted: 1 time

Re: High DPI question

Post by Lembasts »

So the ultimate question is - why would the width property return zero when it has clearly been defined?
And why would it do this for some listviews and not others?
This topic is 1 year and 3 weeks 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