Weird Control.Margin values when screen DPI is greater than 100%
- Dominant language
- C#
- Stars
- 4.9k
- Forks
- 1.1k
- Avg merge
- 20h 23m
- Merged PRs (30d)
- 103
Description
### .NET version
.NET8.0, .NET6.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+?
No
### Issue description
[TestUpDown.zip](https://github.com/dotnet/winforms/files/13511266/TestUpDown.zip)
I have done a simple test project with NumericUpDown and Button controls.
1. Controls are placed direct to the Form.
2. Controls are placed on a TableLayoutPanel (Parent is the Form)
3. Controls are placed on a Panel (Parent is the Form)
4. Controls are placed on a Panel (Parent is an other Panel which is placed on the Form)
When pressing the Buttons one gets a MessageBox with information about DisplayRectangle and Margin values for the Button and NumericUpDown.
When you run with 100% screen DPI the Margin values are all set to 3. But when you run with a higher DPI the Margin values are weird. For example in test case 4 with DPI=150% I get NumericUpDown Margin values 9, 13, 9, 13 and for the Button I get 4, 5, 4, 5.
In the project I have set ApplicationHighDpiMode to PerMonitorV2. But it seems that the issue is also present in other DpiModes.
### Steps to reproduce
Run the project with different DPI values and press the Buttons and notice the MessageBox values.
Form at 100% DPI

MessageBox with DPI=150% when pressing button4

Contributor guide
Assessment
This issue has not been assessed yet.