dotnet / dotnet/winforms

ContainerControl incorrectly scales multiple times when moving from one ControlCollection to another.

Open
#12,851 11 comments 0 reactions 1 assignee Claimed by @LeafShi1 View on GitHub
:boom: regression-release area-HDPI
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?

Yes

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

Sample project appears to work in .NET 6.

### Issue description

Setup:
The parent form has AutoScaleMode set to DPI, and is being shown on a display with resolution that would cause the form to scale (i.e. not 100%).

Issue:
When a ContainerControl is removed from one Controls collection and added to another, the ContainerControl is scaled multiple times (based on the default and inherited fonts?), leading to the size of the control changing each time it is moved.

Notice in the animation below, the size of the TextBox remains static, while the red ContainerControl gets longer.
![Image](https://github.com/user-attachments/assets/515b40bc-e392-4ce8-9d0f-170ba2088306)

### Steps to reproduce

[ContainerControlSample.zip](https://github.com/user-attachments/files/18576586/ContainerControlSample.zip)

1. Run the sample on a display set above 100%.
2. Click button3 on the initial Form2 to pull up the Form4 with the issue.
3. Repeatedly click button1 on Form4.

Results:
The red ContainerControl gets longer with each button1 click.

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.