dotnet / dotnet/winforms

Scaling of list type controls fails, creeps upwards in SpliContainer

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

Description

### .NET version

This relates to .net **8.0**, **7.0** and **6.0**

### Did it work in .NET Framework?

No

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

There are similar issues with .Net Framework, e.g. 4.8

### Issue description

## Description
### Environment
A .Net 8.0 Forms project set for PerMonitorV2

### Issue
When moving a form with a list-type control bound by a **bottom anchor** to a splitcontainer back and forth between monitors with different scaling, it usually makes the list bottom creep upwards, (Tested with 100% versus all scale-factors from 125% to 350%).
(Placed directly on a form, and not within a control, makes it collapse faster)

### Known workaround:
Place the list with DockStyle.Full in a dummy panel, giving the dummy panel the same size/position/anchors as the list had.

### Suspected cause
As list type controls have heights aligned with a multipla of the items, rounding errors can cause calculating the number of items there are room for to be rounded down, e.g. 10.9999 → 10, so a tiny addition to the height of say ½ or 1 pixel before dividing with the item-height and truncating might fix it.

### Here an example
A split container, and in one panel a ListBox, and a sub-panel with another ListBox filling that sub-panel
![WinFormsAppCreepingListOnRescale_workaround](https://github.com/dotnet/winforms/assets/24905467/d1e576ab-64fa-4bf5-a878-f600bfdda723)

### Code example, including the mentioned known workaround
[WinFormsAppCreepingListOnRescale_workaround_source.zip](https://github.com/dotnet/winforms/files/13403226/WinFormsAppCreepingListOnRescale_workaround_source.zip)

### Steps to reproduce

1. Start VS 2022 17.8
2. Create a new .Net 8.0 WinForm app
3. Make sure the proj file has
`PerMonitorV2`
4. Tools DoubleClick to add a SplitContainer, covering the whole form
5. Change the splitters Orientation to Horizontal
6. In the upper panel, ToolBox DoubleClick ListBox (just leave at default six items height)
7. Give the list a Bottom Anchor
8. Run
9. Move the app back and forth between monitors with 100% and non 100% scaling, e.g. 100% ↔ 125 %.
10. If you by a lucky punch do not see the issue, adjust the splitter slightly and retry the move

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.