dotnet / dotnet/winforms

Anchored controls scale incorrectly on multi-monitor setup using HDPI PerMonitorV2

Open
#10,958 6 comments 2 reactions 0 assignees View on GitHub
area-HDPI-PMv2
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
1d 13m
Merged PRs (30d)
85

Description

### .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
![grafik](https://github.com/dotnet/winforms/assets/23245821/ffb95d4c-df7a-4af6-bdc0-2669e91219a6)
![grafik](https://github.com/dotnet/winforms/assets/23245821/eecf184f-db10-4d76-88aa-6e8b54f91c12)
![grafik](https://github.com/dotnet/winforms/assets/23245821/f6a08dc3-bd92-4683-82d8-980be5adeee8)

#### .NET 8.0
Loaded on 100 % monitor:
![grafik](https://github.com/dotnet/winforms/assets/23245821/fd1687f9-328a-4aba-9bd4-0fd7305103c8)
Dragged to 150 % monitor first time:
![grafik](https://github.com/dotnet/winforms/assets/23245821/40b43398-59d6-467d-9b7b-1b2e66680037)
Dragged back to 100 % monitor first time:
![grafik](https://github.com/dotnet/winforms/assets/23245821/b88dd9d4-73ea-4d82-b85d-7507d59eae3f)
Dragged back to 150 % monitor second time:
![grafik](https://github.com/dotnet/winforms/assets/23245821/ff492040-a123-46f6-92d9-37e4accd7af9)
Dragged back to 100 % monitor second time:
![grafik](https://github.com/dotnet/winforms/assets/23245821/a1ed4e63-3fe1-44e4-b76e-d1c39bb9fdf8)
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:
![grafik](https://github.com/dotnet/winforms/assets/23245821/cbcec132-9243-47e6-b368-e26b716cedaf)
Dragged back to 100 % monitor first time:
![grafik](https://github.com/dotnet/winforms/assets/23245821/2f01b52f-7ed0-4910-812d-139b2968c7bd)
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

1. Create a new WinForms project targeting .NET 8.0.
2. Add a button to the form.
3. Drag it bigger so it "anchors" to the edges.
4. Set the "Anchor" property to "Top, Bottom, Left, Right".
5. Start the program on a 100 % scaled monitor.
6. Drag it to a higher scaled (e.g. 150 %) monitor.
7. Drag it back to the 100 % monitor.

Example Project:
[Test.zip](https://github.com/dotnet/winforms/files/14419738/Test.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.