HDPI: Position of a Modal-Form (and Modeless) is not centered to parent
- Dominant language
- C#
- Stars
- 4.9k
- Forks
- 1.1k
- Avg merge
- 20h 23m
- Merged PRs (30d)
- 103
Description
### .NET version
.NET SDK:
Version: 7.0.404
Commit: 22f221a24c
### Did it work in .NET Framework?
Not tested/verified
### Did it work in any of the earlier releases of .NET Core or .NET 5+?
The behaviour on .NET 6 is difference to .NET 7, but also not correct.
### Issue description
I have a Form that is opened as Modal (.ShowDialog()) with `StartPosition = FormStartPosition.CenterParent;`
But on my Secondary-Screen with 100% scaling, the Modal Dialog is not centered to it's parent. But a Modeless Dialog (.Show()) is centered!
On my Main-Screen with 125% scaling, the Modal Dialog is correctly centered, but the Modeless Dialog is not centered.
However if I call `CenterToParent();` in Load-Event of the Form, the form is correctly centered.


The fix of issue [#5729](https://github.com/dotnet/winforms/issues/5729) seems not handle this case.
In .NET Framework 4.7.2 it seems that Modless Dialogs never centered.
### Steps to reproduce
Create a new Default .NET Winforms App.
Setup the DpiAwareness Mode in Main()-Method
`Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);`
Create a second Form that is called from the Mainform.
Second Form is set to `StartPosition = FormStartPosition.CenterParent;`
```
...
// Show as Modal Dialog
DialogForm dialogForm = new DialogForm();
dialogForm.ShowDialog(this);
...
// Show as Modeless Dialog
Form dialogForm = new DialogForm();
dialogForm.Show(this);
...
```
[Dialog_CenterParent.zip](https://github.com/dotnet/winforms/files/13546509/Dialog_CenterParent.zip)
Contributor guide
Assessment
This issue has not been assessed yet.