Skip to content

Do not activate the form if MinimumSize changes #13715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

LeafShi1
Copy link
Member

@LeafShi1 LeafShi1 commented Jul 18, 2025

Fixes #13698

Root Cause

In the original code, changing the MinimumSize of a form calls SetWindowPos with the flag SWP_NOZORDER. While this ensures that the Z-order of the forms is unchanged, it is not enough to prevent the affected forms from becoming active.

Proposed changes

  • In UpdateMinimumSize of Form.cs add SET_WINDOW_POS_FLAGS.SWP_NOACTIVATE so that the form is not automatically activated when the MinimumSize property changes

Customer Impact

  • Setting MinimumSize will not activate form

Regression?

  • No

Risk

  • Minimal

Screenshots

Before

BeforeChange.mp4

After

AfterChanges.mp4

Test methodology

  • Manually
  • Unit test

Test environment(s)

  • .net 10.0.0-preview.7.25365.101
Microsoft Reviewers: Open in CodeFlow

@LeafShi1 LeafShi1 requested a review from a team as a code owner July 18, 2025 03:29
@LeafShi1 LeafShi1 requested a review from Copilot July 18, 2025 03:29
Copy link
Contributor

@Copilot 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 fixes an issue where changing a form's MinimumSize property would unintentionally activate the form, disrupting the display order of multiple forms. The fix adds the SWP_NOACTIVATE flag to prevent unwanted form activation during minimum size updates.

  • Adds SWP_NOACTIVATE flag to SetWindowPos call in UpdateMinimumSize method
  • Includes a unit test to verify the fix prevents display order changes

Reviewed Changes

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

File Description
src/System.Windows.Forms/System/Windows/Forms/Form.cs Adds SWP_NOACTIVATE flag to prevent form activation when updating minimum size
src/test/integration/UIIntegrationTests/FormTests.cs Adds test to verify form display order remains unchanged when MinimumSize is set
Comments suppressed due to low confidence (2)

src/test/integration/UIIntegrationTests/FormTests.cs:169

  • The test assertion logic is flawed. TopMost is a property that can be set independently and doesn't indicate display order, while Focused only tells us about input focus, not visual z-order. This test may produce false positives or negatives. Consider using Windows API calls to check actual z-order or a more reliable method to verify form layering.
        Assert.True(form2.TopMost || form2.Focused, "Form2 should be displayed in front of Form1");

src/test/integration/UIIntegrationTests/FormTests.cs:175

  • Same assertion logic issue as line 169. The test uses the same flawed logic to verify the fix worked. A robust test should verify that the z-order or activation state hasn't changed, rather than relying on TopMost or Focused properties which don't accurately represent visual display order.
        Assert.True(form2.TopMost || form2.Focused, "Form2 should still be displayed in front after setting MinimumSize");

Copy link

codecov bot commented Jul 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 51.58047%. Comparing base (118a672) to head (72a84c0).
Report is 11 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (118a672) and HEAD (72a84c0). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (118a672) HEAD (72a84c0)
Debug 3 2
test 1 0
Additional details and impacted files
@@                 Coverage Diff                  @@
##                main      #13715          +/-   ##
====================================================
- Coverage   76.82947%   51.58047%   -25.24901%     
====================================================
  Files           3257        2063        -1194     
  Lines         642592      287762      -354830     
  Branches       47565       42059        -5506     
====================================================
- Hits          493700      148429      -345271     
+ Misses        145232      136448        -8784     
+ Partials        3660        2885         -775     
Flag Coverage Δ
Debug 51.58047% <100.00000%> (-25.24901%) ⬇️
integration 18.99905% <100.00000%> (+0.00886%) ⬆️
production 51.58047% <100.00000%> (+0.13880%) ⬆️
test ?
unit 48.95990% <100.00000%> (+0.13918%) ⬆️

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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@Epica3055 Epica3055 left a comment

Choose a reason for hiding this comment

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

looks good

Copy link
Member

@ricardobossan ricardobossan left a comment

Choose a reason for hiding this comment

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

All LGTM!

@LeafShi1 LeafShi1 merged commit 3ae6410 into dotnet:main Jul 23, 2025
9 checks passed
@filipnavara
Copy link
Member

Thanks!

@LeafShi1 LeafShi1 deleted the Issue_13698_update_UpdateMinimumSize_Form branch July 29, 2025 01:01
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.

Setting MinimumSize activates the window
5 participants