Skip to content

Commit 3ae6410

Browse files
authored
Do not activate the form if MinimumSize changes (#13715)
## 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 <!-- We are in TELL-MODE the following section must be completed --> ## Customer Impact - Setting MinimumSize will not activate form ## Regression? - No
2 parents 021d7ee + 72a84c0 commit 3ae6410

File tree

2 files changed

+23
-1
lines changed
  • src
    • System.Windows.Forms/System/Windows/Forms
    • test/integration/UIIntegrationTests

2 files changed

+23
-1
lines changed

src/System.Windows.Forms/System/Windows/Forms/Form.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ private void UpdateMinimumSize(Size value, bool updateFormSize = true)
13681368
Location.Y,
13691369
Size.Width,
13701370
Size.Height,
1371-
SET_WINDOW_POS_FLAGS.SWP_NOZORDER);
1371+
SET_WINDOW_POS_FLAGS.SWP_NOZORDER | SET_WINDOW_POS_FLAGS.SWP_NOACTIVATE);
13721372
}
13731373
}
13741374

src/test/integration/UIIntegrationTests/FormTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,26 @@ await RunFormWithoutControlAsync(
152152
},
153153
testDriverAsync);
154154
}
155+
156+
[WinFormsFact]
157+
public void Form_MinimumSize_DoesNotChangeDisplayOrder()
158+
{
159+
// Initialize Form1 and Form2.
160+
using Form form1 = new Form { Text = "Form1" };
161+
using Form form2 = new Form { Text = "Form2" };
162+
163+
// Display the forms.
164+
form1.Show();
165+
form2.Show();
166+
167+
// Set initial hierarchy: Form2 should be displayed in front of Form1.
168+
form2.BringToFront();
169+
Assert.True(form2.TopMost || form2.Focused, "Form2 should be displayed in front of Form1");
170+
171+
// Set the MinimumSize property of Form1.
172+
form1.MinimumSize = new Size(300, 300);
173+
174+
// Verify the hierarchy remains unchanged.
175+
Assert.True(form2.TopMost || form2.Focused, "Form2 should still be displayed in front after setting MinimumSize");
176+
}
155177
}

0 commit comments

Comments
 (0)