Skip to content
Open
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
9 changes: 7 additions & 2 deletions src/System.Windows.Forms/System/Windows/Forms/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5731,6 +5731,13 @@ public DialogResult ShowDialog(IWin32Window? owner)
// to CreateControl().
_dialogResult = DialogResult.None;

// Set dialog owner before CreateControl() so that
// FillInCreateParamsStartPosition can access it when positioning maximized forms
if (owner is not null && !ownerHwnd.IsNull)
{
Properties.AddOrRemoveValue(s_propDialogOwner, owner);
}

// If "this" is an MDI parent then the window gets activated,
// causing GetActiveWindow to return "this.handle"... to prevent setting
// the owner of this to this, we must create the control AFTER calling
Expand All @@ -5750,8 +5757,6 @@ public DialogResult ShowDialog(IWin32Window? owner)
// So, it is necessary to not set the owner before creating the handle. Otherwise,
// the window may never receive Dpi changed event even if its parent has different Dpi.
// Users at runtime, has to move the window between the screens to get the Dpi changed events triggered.

Properties.AddOrRemoveValue(s_propDialogOwner, owner);
if (owner is Form form && owner != oldOwner)
{
Owner = form;
Expand Down
Loading