-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Do not activate the form if MinimumSize changes #13715
Conversation
There was a problem hiding this 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 toSetWindowPos
call inUpdateMinimumSize
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, whileFocused
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
orFocused
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");
Codecov ReportAll modified and coverable lines are covered by tests ✅
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
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All LGTM!
Thanks! |
Fixes #13698
Root Cause
In the original code, changing the MinimumSize of a form calls
SetWindowPos
with the flagSWP_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
UpdateMinimumSize
of Form.cs addSET_WINDOW_POS_FLAGS.SWP_NOACTIVATE
so that the form is not automatically activated when theMinimumSize
property changesCustomer Impact
Regression?
Risk
Screenshots
Before
BeforeChange.mp4
After
AfterChanges.mp4
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow