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