因此,在我的工具中,我编写了一个功能,将我的wpf窗口停靠在屏幕的右侧或左侧。它目前支持多个显示器,并在对接之前考虑应用程序所在的屏幕。
然而,该功能似乎不适用于单屏计算机,我不完全确定为什么会这样。当我点击“对接”对话框时按钮似乎将窗口停靠在屏幕上。然而,'离开'对接功能工作正常。有谁知道为什么会这样?我有一台4k单显示器笔记本电脑。
Dock Left Works正确 - 单个和多个监视器
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;
Dock Right / BROKEN - 仅适用于多台显示器
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;