dotnet / dotnet/winforms

MicrosoftForm Size Is Not Updated Correctly When DPI Scaling Exceeds 200

Open
#14,197 3 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
20h 23m
Merged PRs (30d)
103

Description

### **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

* 200% Scaling:

Image

* 225% Scaling:

Image

* 250% Scaling:

Image

* 300% Scaling:

Image

* 350% Scaling:

Image

* 400% Scaling

Image

* 450% Scaling

Image

* 500% Scaling

Image

### **SimpleSample**

[MicrosoftFormSimpleSample.zip](https://github.com/user-attachments/files/24524914/MicrosoftFormSimpleSample.zip)

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

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

### Questions

* Is this a known WinForms rendering issue when controls are anchored on high DPI displays (scaling >200%)?
* Does the size mismatch impact layout consistency, usability, or accessibility in applications?
* Are there any recommended workarounds or fixes (e.g., measuring after OnHandleCreated, adjusting DPI awareness, or other approaches)?

### Environment

.NET Framework / .NET: .NET Framework
Windows Version: Windows 11
Display Scaling Tested: 125%, 150%,175%,200%, 225%,250%,300%,350%,400%,450%
Control Behavior: Control is anchored to the parent form
Custom Styling: None applied

### Additional Notes:

* No custom drawing or styling is used.
* Issue persists consistently across multiple scaling levels when the control is anchored.
* The confusion arises because the size differs depending on whether it is measured after InitializeComponent or after OnHandleCreated

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.