我在多显示器系统和最大化我的无边界 WPF C# .NET 4.0 窗口时遇到问题。一台显示器是 1680x1050(主要),第二台是 1920x1080(次要)。当我在主屏幕上最大化我的窗口时 - 没有问题,即使我切换这两个的顺序。但是每次我试图在辅助屏幕上最大化它时,它都会被切断到主显示器的大小。我看到窗口大小是适当的,但这不起作用。
获取监视器的大小:
private System.Windows.Forms.Screen GetCurrentScreen()
{
System.Drawing.Point centerPoint = new System.Drawing.Point((int)(Left + Width / 2), (int)(Top + Height / 2));
foreach (System.Windows.Forms.Screen s in System.Windows.Forms.Screen.AllScreens)
{
if (s.Bounds.Contains(centerPoint))
{
return s;
}
}
return null;
}
最大化:
private void Maximize
{
if (this.WindowState == WindowState.Normal)
{
var scr = GetCurrentScreen();
//this.MaxHeight = scr.WorkingArea.Height;
//this.MaxWidth = scr.WorkingArea.Width;
if (scr != null)
{
if (scr.Primary)
{
this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
this.MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth;
}
else
{
this.MaxHeight = double.PositiveInfinity; //even ridiculous values don't work
this.MaxWidth = double.PositiveInfinity;
this.Height = scr.WorkingArea.Height; // correct values of 2nd screen
this.Width = scr.WorkingArea.Width;
}
}
else
{
this.MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
this.MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth;
}
this.WindowState = WindowState.Maximized;
}
我得到的是:http: //imgur.com/ZYzVV9Q,yf7lSfY#1
我想要什么:http: //imgur.com/ZYzVV9Q,yf7lSfY#0
谢谢