-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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:
- 125% Scaling:
- 150% Scaling:
- 175% Scaling:
- 225% Scaling:
- 250% Scaling:
- 300% Scaling:
- 400% Scaling
- 500% Scaling
SimpleSample
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.