我正在尝试使用媒体元素创建一个wpf视频播放器。我的目标是为该应用程序制作多个窗口。每个窗口都会显示在不同的显示器上。就像MainWindow将获得主显示器的分辨率并调整自身以全屏显示。辅助监视器上的第二个窗口等等......
到目前为止,我已在主监视器上制作了MainWindow全屏。但我不知道如何用它的分辨率在第二台显示器上显示第二个窗口。请帮忙。
答案 0 :(得分:6)
最简单的选择是显示它。在show()方法之后,调整它的大小。
// display on second window
NewWindow win = new NewWindow();
System.Windows.Forms.Screen s1 = System.Windows.Forms.Screen.AllScreens[2];
System.Drawing.Rectangle r1 = s1.WorkingArea;
win.WindowState = System.Windows.WindowState.Normal;
win.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
win.Top = r1.Top;
win.Left = r1.Left;
win.Show();
win.WindowState = System.Windows.WindowState.Maximized;
答案 1 :(得分:0)
每个屏幕都有空间坐标,你实际上并没有在其他屏幕的坐标上放置一个窗口。
在这台机器上-1280,0是左侧监视器,0,0是主监视器,1280,0是右侧监视器。不知道多屏幕操作的程序通常对此没有任何问题,尽管当放置在左侧监视器上时,足够老的东西可以做一些奇怪的事情(试图阻止弹出窗口离开屏幕边缘,不知道负面坐标可见。)
关于定位屏幕,请参阅:How to easily find screen location of form Location in multi-monitor environment?
答案 2 :(得分:0)
您可以尝试这样的事情:
private System.Windows.Forms.Screen findScreen(string screenName) {
System.Windows.Forms.Screen res = System.Windows.Forms.Screen.AllScreens.FirstOrDefault(s => s.DeviceName == screenName);
if (res == null)
res = System.Windows.Forms.Screen.AllScreens[0];
return res;
}
private void setupForms() {
System.Windows.Forms.Screen mainScreen = findScreen(@"\\.\DISPLAY2");
FrmMain frmMain = new FrmMain()
{
WindowStartupLocation = WindowStartupLocation.Manual,
WindowState = System.Windows.WindowState.Normal,
Left = mainScreen.WorkingArea.Left,
Top = mainScreen.WorkingArea.Top,
Width = mainScreen.WorkingArea.Width,
Height = mainScreen.WorkingArea.Height
};
System.Windows.Forms.Screen secondaryScreen = findScreen(@"\\.\DISPLAY1");
FrmSecondary frmSecondary = new FrmSecondary()
{
WindowStartupLocation = WindowStartupLocation.Manual,
WindowState = System.Windows.WindowState.Normal,
Left = secondaryScreen.WorkingArea.Left,
Top = secondaryScreen.WorkingArea.Top,
Width = secondaryScreen.WorkingArea.Width,
Height = secondaryScreen.WorkingArea.Height
};
}
答案 3 :(得分:0)
我将更新@romanoza的答案
private void SetupWindows()
{
System.Windows.Forms.Screen mainScreen = Screen.AllScreens[0]; ;
WinLeft leftWin = new WinLeft()
{
WindowStartupLocation = WindowStartupLocation.Manual,
WindowState = System.Windows.WindowState.Normal,
Left = mainScreen.WorkingArea.Left,
Top = mainScreen.WorkingArea.Top,
Width = mainScreen.WorkingArea.Width,
Height = mainScreen.WorkingArea.Height
};
System.Windows.Forms.Screen secondaryScreen = Screen.AllScreens[1];
WinRight rightWin = new WinRight()
{
WindowStartupLocation = WindowStartupLocation.Manual,
WindowState = System.Windows.WindowState.Normal,
Left = secondaryScreen.WorkingArea.Left,
Top = secondaryScreen.WorkingArea.Top,
Width = secondaryScreen.WorkingArea.Width,
Height = secondaryScreen.WorkingArea.Height
};
leftWin.Show();
leftWin.WindowState = WindowState.Maximized;
rightWin.Show();
rightWin.WindowState = WindowState.Maximized;
rightWin.Owner = leftWin;
}