dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.29k stars 957 forks source link

Anchors of user control don't work when scaling on high DPI (#6381) #11390

Closed frobijn closed 1 month ago

frobijn commented 1 month ago

.NET version

8.0

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Yes: see https://github.com/dotnet/winforms/issues/6381.

Issue description

Issue #6381 is back. The issue is present when the form is first displayed; resizing afterwards works as expected.

Steps to reproduce

The issue #6381 contains a demo program. That doesn't work correctly with .NET 8. Its behavior is even worse if

Application.SetHighDpiMode (HighDpiMode.PerMonitorV2);

is added. I've also added

<ApplicationHighDpiMode>SystemAware</ApplicationHighDpiMode>
<ForceDesignerDpiUnaware>true</ForceDesignerDpiUnaware>

to the project file as adviced in https://github.com/dotnet/winforms/blob/main/docs/designer/designer-high-dpi-mode.md and opened the forms in the designer, but that did not have any effect.

Updated demp program: ControlScalingBug_Net8.zip

Application behavior on the high-DPI main monitor: https://github.com/dotnet/winforms/assets/13610628/882c12fb-c8df-4bfa-8198-dbb118ed09c8

Application behavior on the normal-DPI secondary monitor: https://github.com/dotnet/winforms/assets/13610628/b4ba58ab-2e04-41a8-8e3b-ad8a5bf6e4fe

elachlan commented 1 month ago

@Olina-Zhang can your team please confirm this issue?

Zheng-Li01 commented 1 month ago

@elachlan @frobijn this issue is about the Anchor property, which can resolved by adding the System.Windows.Forms.AnchorLayoutV2": true in the ControlScalingBug.runtimeconfig.json file a below screenshot. please have a try.

Refer the workaround from https://github.com/dotnet/winforms/issues/10382#issuecomment-1859448756 Issue11390

frobijn commented 1 month ago

Yes, that solves the issue. The option "System.Windows.Forms.AnchorLayoutV2" as a solution to problems with anchoring is impossible to find with a search engine, so it doesn't exist :-)