winforms
winforms copied to clipboard
Anchored controls scale incorrectly on multi-monitor setup using HDPI PerMonitorV2
.NET version
.NET 8.0
Did it work in .NET Framework?
Not tested/verified
Did it work in any of the earlier releases of .NET Core or .NET 5+?
On .NET 6 the issue isn't present this severely but present in a different way
Issue description
When creating a WinForms app targeting .NET 8.0 with an auto-scaleable element anchored to at least two opposing sites on a form (e.g. a button or text box) and the project being set to HDPI mode PerMonitorV2
, the element will wildly change it's size (up to being completely invisible) when dragged between monitors with different HDPI settings (e.g. one scaled to default 100 %, one to 150 %).
Setup
.NET 8.0
Loaded on 100 % monitor:
Dragged to 150 % monitor first time:
Dragged back to 100 % monitor first time:
Dragged back to 150 % monitor second time:
Dragged back to 100 % monitor second time:
Dragged back to 150 % monitor third time:
Same as second time.
.NET 6
Loaded on 100 % monitor:
Same as in .NET 8.
Dragged to 150 % monitor first time:
Dragged back to 100 % monitor first time:
Dragged to 150 % monitor second time:
Same as first time.
PS
I think this issue is different from e.g. #8157 because that one is explicitly about elements in SplitContainers, while mine is about elements directly on forms.
Steps to reproduce
- Create a new WinForms project targeting .NET 8.0.
- Add a button to the form.
- Drag it bigger so it "anchors" to the edges.
- Set the "Anchor" property to "Top, Bottom, Left, Right".
- Start the program on a 100 % scaled monitor.
- Drag it to a higher scaled (e.g. 150 %) monitor.
- Drag it back to the 100 % monitor.
Example Project: Test.zip
@Olina-Zhang could your team please test this?
@elachlan yes, we can repro this issue with .NET 8.0 and latest .NET 9.0.100-preview.3.24127.9 SDK, please check below video.
Launch test app on 100% primary monitor and then move form to 175% secondary monitor.
https://github.com/dotnet/winforms/assets/45864985/e09c4b32-0391-4fa3-8063-35ea34291873
In above video result, I tried to add the runtimeconfig.template.json file with below codes in test project, that can improve most problems, but not solve all issues.
{
"configProperties": {
"System.Windows.Forms.AnchorLayoutV2": true
}
}
Launched on 100% primary monitor
Moved to 175% secondary monitor
Attached is another .NET8 sample where moving the form from screen 1 at 100% to screen 2 at 125% and back causes broken layout. DpiAwarenessHighDpiModePMV2.zip
I tested it with System.Windows.Forms.AnchorLayoutV2
= true
and false
in "runtimeconfig.template.json":
{
"configProperties": {
"System.Windows.Forms.AnchorLayoutV2": true
}
}
Both modes show different behavior, but the result is broken for both of them. This blocks us from supporting DPI awareness in our application (since our first attempt to do so in 2016 :-( ).
This is the result for AnchorLayoutV2 = true" - start with the top left image, a bit below to the right is the result of moving the form to the 125% screen, then below to the left the form back at 100% and so on:
And this is the result for "AnchorLayoutV2 = false" (old behavior).
I also noted that the form has different sizes sometimes when moving to the 125% screen.
I don't like the fact that this issue has a milestone "Future" - as I wrote above this blocks us from activating dpi awareness. I want to avoid redesigning all forms in our app and replace Anchor layouts with Dock.