Skip to content

Weird Control.Margin values when screen DPI is greater than 100% #10402

Description

@harborsiem

.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
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
TestUpDown

MessageBox with DPI=150% when pressing button4
TestUpDown150MessageBox

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-HDPIHDPI, not specific to Dpi mode of app

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions