Skip to content

.NET Core: Form Size Not Updating Correctly When DPI Scaling Exceeds 200% #14200

@vimalrajsf5014

Description

@vimalrajsf5014

.NET version

.NET 90

Did it work in .NET Framework?

No

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

Not applicable — this issue was observed on .NET Framework. I have not verified behavior on earlier .NET Core or .NET 5+ releases.

Issue description

When adding a control of size 500x500 pixels (at 100% scaling = 96 DPI) to a Microsoft Form, the control is anchored and its size is measured at different points in the lifecycle:

  • After InitializeComponent
  • After OnHandleCreated
  • At 100% scaling, these measurements are identical.
  • At DPI scaling greater than 200%, the control size differs depending on when it is measured, which causes layout problems.

I have attached a simple sample project and images that demonstrate the issue.

Screenshots

  • 100% Scaling:
Image
  • 125% Scaling:
Image
  • 150% Scaling:
Image
  • 175% Scaling:
Image
  • 225% Scaling:
Image
  • 250% Scaling:
Image
  • 300% Scaling:
Image
  • 400% Scaling
Image
  • 500% Scaling
Image

SimpleSample

MicrosoftFormSimpleSample.zip

Actual Behavior

  • For DPI scaling greater than 200%, the control’s size measured after InitializeComponent and after OnHandleCreated differs.
  • This mismatch causes layout problems and breaks anchored layouts.

Expected Behavior

  • The control size should remain the same between creation and display, regardless of the DPI scaling level.
  • Anchored layouts should not break due to differences between InitializeComponent and OnHandleCreated measurements.

Steps to reproduce

Step 1 : Run the attached simple sample project.
Step 2 : Click the MicrosoftForm button.
Step 3 : Ensure that DPI awareness is set to true in the app.manifest file.
Step 4 : The sample creates a control sized 500x500 pixels at 100% scaling (96 DPI) and anchors it to the parent form.
Step 5 : Observe the control size measured:

  • After InitializeComponent
  • After OnHandleCreated

Step 6 : Change the display scaling level to 200% or higher (e.g., 225%).
Step 7 : Compare the measurements — they should be the same, but at scaling >200% the values differ.

Metadata

Metadata

Labels

area-HDPI-SAIssues related to high DPI SystemAware mode

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions