[英]How can I open a file via click it in windows with a WPF app?
[英]How can I open a new WPF windows in second monitor?
我正在尝试从位于主监视器中的 Windows 在第二个监视器中打开一个新的 WPF Window。 根据我在其他线程和讨论中创建的内容,我写了这个:
System.Windows.Forms.Screen s1 = System.Windows.Forms.Screen.AllScreens[1];
System.Drawing.Rectangle r1 = s1.WorkingArea;
form.WindowState = System.Windows.WindowState.Normal;
form.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
form.Top = r1.Top;
form.Left = r1.Left;
form.Show();
form.WindowState = System.Windows.WindowState.Maximized;
但此代码不起作用:新的 window 显示在主监视器中。 我该如何解决这个问题? 谢谢。
您需要找到具有Primary==false
的第一个监视器。
例如像这样:
System.Windows.Forms.Screen s1 = System.Windows.Forms.Screen.AllScreens.
.First(scr => !scr.Primary);
您也可以使用 Win API 代替System.Windows.Forms.Screen
。 一个例子在这里: https://ru.stackoverflow.com/a/693607/399133
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.