我想在辅助监视器上显示一个窗口,如下所示:
Queue<string> itemQueue = new Queue<string>();
MonitorWindow monitor = new MonitorWindow(itemQueue);
var secondaryScreen = System.Windows.Forms.Screen.AllScreens.Where(s => !s.Primary)
.FirstOrDefault();
if (secondaryScreen != null)
{
monitor.WindowStartupLocation = WindowStartupLocation.Manual;
var workingArea = secondaryScreen.WorkingArea;
monitor.Left = workingArea.Left;
monitor.Top = workingArea.Top;
monitor.Width = workingArea.Width;
monitor.Height = workingArea.Height;
monitor.Show();
}
属性具有正确的值,但这会使主监视器上的Window最大化。你能救我吗?
答案 0 :(得分:2)
好的,我已经修复了问题,在MonitorWindow的XAML代码中删除了属性WindowState =“Maximized”,并按如下方式更改了程序:
Queue<string> itemQueue = new Queue<string>();
MonitorWindow monitor = new MonitorWindow(itemQueue);
var secondaryScreen = System.Windows.Forms.Screen.AllScreens.Where(s => !s.Primary).FirstOrDefault();
if (secondaryScreen != null)
{
if (!monitor.IsLoaded)
monitor.WindowStartupLocation = WindowStartupLocation.Manual;
var workingArea = secondaryScreen.WorkingArea;
monitor.Left = workingArea.Left;
monitor.Top = workingArea.Top;
monitor.Width = workingArea.Width;
monitor.Height = workingArea.Height;
// If window isn't loaded then maxmizing will result in the window displaying on the primary monitor
monitor.Show();
if (monitor.IsLoaded)
monitor.WindowState = WindowState.Maximized;
}