dotnet / dotnet/winforms

When a Form is opened and StartPosition is CenterParent, it is opened always on the main monitor when the value of WindowState is Maximized regardless of parent's monitor

Open
#8,932 5 comments 0 reactions 0 assignees View on GitHub
:beetle: bug :boom: regression-release :construction: work in progress area-HDPI-PMv2
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
1d 13m
Merged PRs (30d)
85

Description

### .NET version

SDK DE .NET:
Version: 7.0.202
Commit: 6c74320bc3

Entorno de tiempo de ejecución:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.202\

Host:
Version: 7.0.4
Architecture: x64
Commit: 0a396acafe

### Did it work in .NET Framework?

Yes

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

_No response_

### Issue description

When a Form is opened and StartPosition is CenterParent, it is opened always on the main monitor when the value of WindowState is Maximized.

If a window is opened on the secondary monitor, instead of being displayed on that monitor it is displayed on the primary.

Because of this, we cannot open maximized forms by default on the same monitor as the parent window.

Here is a test form that demonstrates the observed behavior:

[Form1.vb](https://pastebin.com/v5beGHEh)
[Form1.Designer.vb](https://pastebin.com/XSCBYR4V)

As a workaround, it is possible to set the WindowState in the overridden OnLoad method. (The "Open form that overrides onLoad normal with center parent without parent" and "Open form that overrides onLoad normal with center parent with parent" buttons in Form1). Although if the form contains many controls and takes time to load, you see a rectangle on the wrong monitor before moving to the correct one.

### Steps to reproduce

**Environment**
2 monitor setup (1920x1080 each)
Left monitor assigned as primary monitor

**Reproduction Steps:**

1. Run the test application
2. Move application window to secondary monitor
3. Click the "Open form normal with center parent" button
4. Close the modal window
5. Click the "Open form maximized with center parent" button

**Expected result**
Both modal windows are displayed on the same monitor as their parent (the secondary monitor)

**Actual result**
In the case of the form with the value FormWindowState.Normal, it is shown in the parent's monitor.
However, in the form with value FormWindowState.Maximized it is always displayed on the main monitor.

**Other observations**
It has also been verified that changing the main monitor in the operating system and executing
the steps according to the change (move the application to the secondary monitor before
clicking on the buttons) the behavior is maintained.

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.