在扩展屏幕上显示表单

在扩展屏幕上显示表单

问题描述:

我想在扩展显示器上显示表单。单击按钮后,下面是我的代码:

I want to display the form on the extended monitor. Below is my code after clicking a button:

primaryDisplay = Screen.AllScreens.ElementAtOrDefault(0);
extendedDisplay = Screen.AllScreens.FirstOrDefault(s => !s.Equals(primaryDisplay)) ?? primaryDisplay;
this.StartPosition = FormStartPosition.Manual;
this.Location = extendedDisplay.Bounds.Location;
this.Show();



但是,表格仍显示在主要表格上。我的代码有什么问题?谢谢。



我的尝试:



扩展后的展示表格屏幕不成功


However, the form is still displayed on the primary one. What is wrong in my code? Thanks.

What I have tried:

Display Form on Extended Screen not successful

在我看到的任何地方都没有定义返回屏幕的顺序:你需要检查Screen.Primary Property(System.Windows.Forms) [ ^ ]而不是依赖于收集中的第一个:

The order in which the screens are returned is not defined anywhere I can see: you need to check the Screen.Primary Property (System.Windows.Forms)[^] rather than rely on the first in the colection:
primaryDisplay = Screen.AllScreens.FirstOrDefault(s => s.Primary);
extendedDisplay = Screen.AllScreens.FirstOrDefault(s => !s.Primary) ?? primaryDisplay;
StartPosition = FormStartPosition.Manual;
Location = extendedDisplay.Bounds.Location;
Show();