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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/System.Windows.Forms/System/Windows/Forms/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ private void UpdateMinimumSize(Size value, bool updateFormSize = true)
Location.Y,
Size.Width,
Size.Height,
SET_WINDOW_POS_FLAGS.SWP_NOZORDER);
SET_WINDOW_POS_FLAGS.SWP_NOZORDER | SET_WINDOW_POS_FLAGS.SWP_NOACTIVATE);
}
}

Expand Down
22 changes: 22 additions & 0 deletions src/test/integration/UIIntegrationTests/FormTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,26 @@ await RunFormWithoutControlAsync(
},
testDriverAsync);
}

[WinFormsFact]
public void Form_MinimumSize_DoesNotChangeDisplayOrder()
{
// Initialize Form1 and Form2.
using Form form1 = new Form { Text = "Form1" };
using Form form2 = new Form { Text = "Form2" };

// Display the forms.
form1.Show();
form2.Show();

// Set initial hierarchy: Form2 should be displayed in front of Form1.
form2.BringToFront();
Assert.True(form2.TopMost || form2.Focused, "Form2 should be displayed in front of Form1");

// Set the MinimumSize property of Form1.
form1.MinimumSize = new Size(300, 300);

// Verify the hierarchy remains unchanged.
Assert.True(form2.TopMost || form2.Focused, "Form2 should still be displayed in front after setting MinimumSize");
}
}