dotnet / dotnet/winforms

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

Open
#14,200 6 comments 0 reactions 1 assignee Claimed by @KlausLoeffelmann View on GitHub
area-HDPI-SA
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
1d 13m
Merged PRs (30d)
85

Description

### .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](https://github.com/user-attachments/files/24554192/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.

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.