Skip to content

Conversation

@LeafShi1
Copy link
Member

@LeafShi1 LeafShi1 commented Dec 12, 2025

Fixes #14101

Proposed changes

  • Add an switch System.Windows.Forms.MirrorTopMostForModalDialogs.
    When enabled, ShowDialog will temporarily set the dialog as TopMost if its owner is TopMost, and restore the original state after closing.
    Default is false to keep current behavior.

Customer Impact

  • With the switch off: No change, modern .NET behavior remains.
  • With the switch on: Modal dialogs owned by TopMost forms will stay above the owner during the modal session, matching .NET Framework behavior.

Regression?

  • Yes

Risk

  • Minimal

Screenshots

Before

If the owner is TopMost and the dialog is not, the dialog can be pushed behind the owner during the modal session.
Image

After

Modal dialogs temporarily become TopMost when the owner is TopMost, and stay above the owner until closed.

Image

Test methodology

  • Manually

Test environment(s)

  • .net 10.0.0-rc.3.25603.106
Microsoft Reviewers: Open in CodeFlow

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an AppContext switch System.Windows.Forms.MirrorTopMostForModalDialogs to restore .NET Framework-like behavior where modal dialogs temporarily inherit the TopMost property from their owner Form during the modal session.

Key Changes:

  • Introduces a new AppContext switch that when enabled, automatically sets TopMost=true on modal dialogs if their owner Form has TopMost=true
  • Restores the original TopMost state after the dialog closes
  • Default behavior is false to maintain current .NET behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/System.Windows.Forms.Primitives/src/System/LocalAppContextSwitches/LocalAppContextSwitches.cs Adds the MirrorTopMostForModalDialogs switch definition and property
src/System.Windows.Forms/System/Windows/Forms/Form.cs Implements the TopMost mirroring logic in ShowDialog method, capturing original state and restoring it after the modal session

@codecov
Copy link

codecov bot commented Dec 12, 2025

Codecov Report

❌ Patch coverage is 25.00000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.15426%. Comparing base (5d64bba) to head (8ff448e).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #14138         +/-   ##
===================================================
+ Coverage   76.01271%   77.15426%   +1.14154%     
===================================================
  Files           3279        3279                 
  Lines         645325      645337         +12     
  Branches       47720       47722          +2     
===================================================
+ Hits          490529      497905       +7376     
+ Misses        145491      143738       -1753     
+ Partials        9305        3694       -5611     
Flag Coverage Δ
Debug 77.15426% <25.00000%> (+1.14154%) ⬆️
integration 18.98449% <25.00000%> (?)
production 52.01885% <25.00000%> (+2.55940%) ⬆️
test 97.40749% <ø> (ø)
unit 49.47059% <25.00000%> (+0.01114%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant