WPF-在多个屏幕中设置多个窗口 [英] WPF-Set multiple windows in multiple screens

查看:973
本文介绍了WPF-在多个屏幕中设置多个窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个wpf应用程序,它同时在两个屏幕上加载多个窗口(当应用程序执行时)。 Windows可以是小屏幕或全屏幕,但它们都在屏幕点(x,y)中为屏幕指定的屏幕(screenIndex)中有一个位置。我的问题是他们正确处理屏幕上的X,Y位置,但它们显示在同一个屏幕上(无论我指定的是什么屏幕)。我尝试了下一个代码选项,但我没有看到可能出现的问题。另外我找不到另一个成功的解决方案:



一个选项:



I have a wpf app wich load multiple windows in two screens at same time (when the app is executed). Windows can be small or full screen but all of them have a location in the screen specified for them (screenIndex) in screen points (x,y). My problem is they process correctly the X,Y location on a screen but they are displayed on the same screen ( no matter what screen I specify). I tried next code options and I don't see what can be the problem . Also I could not found another succesfully solution:

One option:

  private void ShowByCoordinates(Window window, int screenId, int LeftTransform, int TopTransform){
window.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
System.Drawing.Rectangle totalSize = System.Drawing.Rectangle.Empty;
System.Windows.Forms.Screen s0 = System.Windows.Forms.Screen.AllScreens[screenIndex];
                totalSize = System.Drawing.Rectangle.Union(totalSize, s0.Bounds);   


           window.Width = totalSize.Width;
           window.Height = totalSize.Height;

            window.Left = LeftTransform;
            window.Top = TopTransform;
            window.Show();
}



选项2:


Option 2:

System.Windows.Forms.Screen s0 = System.Windows.Forms.Screen.AllScreens[screenId];// My screenId (int) specified
           Rectangle r0 = s0.WorkingArea;
           r0.X = TopTransform;// My int coordinate
           r0.Y = LeftTransform;// My int coordinate
           window.Topmost = true;
           window.Top = r0.X;
           window.Left = r0.Y;
           window.Show();

推荐答案

已应用解决方案:



Solution applied:

private void ShowByCoordinates(Window window, int screenId, int LeftTransform, int TopTransform){
System.Drawing.Rectangle bounds = System.Drawing.Rectangle.Empty;
            System.Windows.Forms.Screen s0 = System.Windows.Forms.Screen.AllScreens[screenId];
            bounds = s0.WorkingArea;
            window.Left = bounds.X + LeftTransform;
            window.Top = bounds.Y + TopTransform;
            window.Show();
}





这很简单,但我确信设置了工作区或类似的东西。



It was pretty simple but I was conviced to set the working area or stuff like that.


这篇关于WPF-在多个屏幕中设置多个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆