Different dialog opening position behavior when starting application from Explorer vs. Command Line/VS/...

Sebastian Fischer 0 Reputation points
2023-06-06T07:41:23.4666667+00:00

Hello,

we have noticed a problematic difference in the automatic positioning of modal dialogs in our Windows application when using multiple monitors:

  • When our application was started from cmd.exe, PowerShell or a different application (like Visual Studio), a modal dialog is automatically opened on the same monitor as the application's main window (or the owning window). This is what we want (automatically cascading positions for sub-(sub-(sub-))dialogs).
  • When our application was started from the Explorer, a modal dialog is always opened on the same monitor, regardless of where the application's main window (or the owning window) is. That's really unexpected for a user.

Here, you can see the relevant code snippet from a .NET WPF application where this problem happens:

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        MainWindow mainWindow = new MainWindow();
        mainWindow.Owner = this;
        mainWindow.ShowDialog();
    }

We can reproduce this problem on Windows 10 (1909, 21H2 and 22H1) using both .NET Framework 4.8 and .NET 6.

Do you have any ideas how to solve this problem?
We want to avoid having to position the dialogs manually in our code, as that becomes quite complicated and error-prone when multiple monitors with different scalings are involved.

Thank you
Sebastian

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,398 questions
{count} votes