Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在单个/多个监视器上停靠WPF窗口_C#_Wpf - Fatal编程技术网

C# 在单个/多个监视器上停靠WPF窗口

C# 在单个/多个监视器上停靠WPF窗口,c#,wpf,C#,Wpf,因此,在我的工具中,我编写了一个函数,将wpf窗口停靠在屏幕的右侧或左侧。它目前支持多个监视器,并在对接应用程序之前考虑应用程序所在的屏幕 然而,这个功能在单屏电脑上似乎不起作用,我也不完全清楚为什么会这样。当我点击“停靠右”按钮时,它似乎将窗口停靠在屏幕之外。不过,“左”停靠功能工作正常。有人知道为什么会这样吗?我有一台4k单显示器笔记本电脑 停靠左侧正常工作-单个和多个监视器 System.Windows.Point cursorPos = PointToScreen(Mouse.GetPo

因此,在我的工具中,我编写了一个函数,将wpf窗口停靠在屏幕的右侧或左侧。它目前支持多个监视器,并在对接应用程序之前考虑应用程序所在的屏幕

然而,这个功能在单屏电脑上似乎不起作用,我也不完全清楚为什么会这样。当我点击“停靠右”按钮时,它似乎将窗口停靠在屏幕之外。不过,“左”停靠功能工作正常。有人知道为什么会这样吗?我有一台4k单显示器笔记本电脑

停靠左侧正常工作-单个和多个监视器

System.Windows.Point cursorPos = PointToScreen(Mouse.GetPosition(this));
            int X = Convert.ToInt32(cursorPos.X);
            int Y = Convert.ToInt32(cursorPos.Y);

            System.Drawing.Point pt = new System.Drawing.Point(X, Y);
            Screen screen = Screen.FromPoint(pt);

            //this.Left = screen.WorkingArea.Left;
            this.Left = screen.Bounds.Left;
System.Windows.Point cursorPos = PointToScreen(Mouse.GetPosition(this));
            int X = Convert.ToInt32(cursorPos.X);
            int Y = Convert.ToInt32(cursorPos.Y);

            System.Drawing.Point pt = new System.Drawing.Point(X, Y);
            Screen screen = Screen.FromPoint(pt);

            this.Left = screen.Bounds.Right - this.Width;
停靠右侧/断开-仅适用于多个监视器

System.Windows.Point cursorPos = PointToScreen(Mouse.GetPosition(this));
            int X = Convert.ToInt32(cursorPos.X);
            int Y = Convert.ToInt32(cursorPos.Y);

            System.Drawing.Point pt = new System.Drawing.Point(X, Y);
            Screen screen = Screen.FromPoint(pt);

            //this.Left = screen.WorkingArea.Left;
            this.Left = screen.Bounds.Left;
System.Windows.Point cursorPos = PointToScreen(Mouse.GetPosition(this));
            int X = Convert.ToInt32(cursorPos.X);
            int Y = Convert.ToInt32(cursorPos.Y);

            System.Drawing.Point pt = new System.Drawing.Point(X, Y);
            Screen screen = Screen.FromPoint(pt);

            this.Left = screen.Bounds.Right - this.Width;