dotnet / dotnet/winforms

Incorrect Z-Order behavior for popup forms in .NET compared to .NET Framework when using SetWindowPos with HWND_TOPMOST

Open
#14,101 9 comments 0 reactions 1 assignee Claimed by @LeafShi1 View on GitHub
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
1d 13m
Merged PRs (30d)
85

Description

### .NET version

.NET SDK:
Version: 10.0.100
Commit: b0f34d51fc
Workload version: 10.0.100-manifests.5fb86115
MSBuild version: 18.0.2+b0f34d51f

### Did it work in .NET Framework?

Yes

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

Didn't check it.

### Issue description

When showing a custom dialog-form from a "pop-up" in Windows Forms on .NET, the Z-Order behaves differently compared to .NET Framework. Specifically:

In **.NET Framework**, calling SetWindowPos with HWND_TOPMOST (-1) works as expected—the popup does not stay topmost permanently.
In **.NET**, the pop-up window remains topmost always, causing UI elements like color pickers or other dialogs to appear behind the pop-up.

This leads to incorrect layering and usability issues in scenarios where multiple pop-ups or dialogs are involved.

### Steps to reproduce

[WinFormsApp9_ZOrderSample.zip](https://github.com/user-attachments/files/23906959/WinFormsApp9_ZOrderSample.zip)

Image

Image

In the attachments, you can find two projects:
WinFormsApp9 - it's .NET application
WindowsFormsApp1 - it's .NET FW application

To reproduce the issue:
1. Run the .NET project
2. Press `button1` - it will open a `special` pop-up window
3. Press `button1` again - it will open Form, using the `ShowDialog` method. As you can see, this form shows behind the pop-up.

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.