Skip to content

Center dialogs and message boxes on their parent window - #106

Merged
Florian Hopfner (FH-Inway) merged 1 commit into
microsoft:masterfrom
tomashan:center-dialogs-on-parent
Sep 20, 2026
Merged

Florian Hopfner (FH-Inway) merged 1 commit into
microsoft:masterfrom
tomashan:center-dialogs-on-parent

Conversation

@tomashan

Copy link
Copy Markdown

Summary

Dialogs and message boxes were shown without an explicit owner, so FormStartPosition.CenterParent had no parent to center against and placement fell back to inconsistent, sometimes off-monitor behavior (especially for non-modal Form.Show(), which never infers an owner).

This change passes the parent form explicitly to ShowDialog/Show/MessageBox.Show throughout MainForm, RDPConnect, AssetLibrarySearch, AddNSG, Parameters, and ChooseProject, so every dialog centers on and stays stacked above its parent, on the parent's monitor.

Test plan

  • Built the solution locally (msbuild 2LCS.sln) — succeeds with no warnings/errors
  • Verified each touched form still compiles and dialog/messagebox calls pass the correct owner

Dialogs and message boxes were shown without an explicit owner, so
FormStartPosition.CenterParent had no parent to center against and
placement fell back to inconsistent, sometimes off-monitor behavior
(especially for non-modal Form.Show(), which never infers an owner).
Passing the parent form explicitly to ShowDialog/Show/MessageBox.Show
throughout MainForm, RDPConnect, AssetLibrarySearch, AddNSG,
Parameters, and ChooseProject makes every dialog center on and stay
stacked above its parent, on the parent's monitor.
@tomashan

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@FH-Inway

Copy link
Copy Markdown
Collaborator

Tomas Hansson (@tomashan) Thanks for reporting and the pr. I will take a closer look after I'm back from vacation.
In the mean time, could you share screenshots that show the issue so it is easier to repro and validate the solution? From the description, it sounds like a multi-monitor setup issue?

@tomashan

Tomas Hansson (tomashan) commented Sep 15, 2026 •

Copy link
Copy Markdown
Author

Florian Hopfner (@FH-Inway) Thanks, no rush - enjoy the rest of your vacation!

Good question, but it's not multi-monitor specific - I can reproduce it on a single monitor too. A screenshot doesn't really capture the bug well, since the issue is that the dialog's position has no relationship to the parent's position at all. Here's a diagram instead:

dialog-position-diagram

Left panel (before the fix): the same main window is shown in two positions (1 and 2). In both cases ShowDialog() / MessageBox.Show() were called with no owner, so FormStartPosition.CenterParent has nothing to center against, and WinForms falls back to a fixed default position - the dialog lands in the same spot every time, regardless of where the parent window actually is.

Right panel (after the fix): with ShowDialog(this) / MessageBox.Show(this, ...), CenterParent has an owner to measure against, so the dialog re-centers on wherever the parent currently sits.

Happy to put together real screenshots too once you're back if that's still useful, but I think this shows the root cause more clearly than a screen capture would.

@FH-Inway
Florian Hopfner (FH-Inway) merged commit d59e9ad into microsoft:master Sep 20, 2026
2 checks passed
@FH-Inway

Copy link
Copy Markdown
Collaborator

Thanks for the diagram, that was helpful.

I tried various ways to reproduce the issue, but was not quite successful. It seems that the issue may only occur with dialogs that are generated during runtime, but have no explicit form defined?

Best result was when I tried the "RDP and passwords > Show passwords" dialog from a cloud hosted instance context menu (right click). There before the pr changes, when having the main window on a monitor different from the main monitor, the dialog is shown near the top left corner of the main monitor. With the pr changes, it shows the dialog on the same monitor as the main form, but still near the top left corner, not centered on the main form.

In any case, the pr changes are looking good, so I went ahead and merged them. This is now available in version 0.54.0. Thanks for the fixes.

In case you want to follow up, I also noticed that the AssetLibrarySearch form does not have the StartPosition property set to CenterParent, causing it to always be displayed on the main monitor near the top left corner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants