我从 Form1 创建 Form2。我希望 Form2 在第二台显示器上打开。我怎么能做到这一点?我使用这段代码:
private void button1_Click(object sender, EventArgs e)
{
Form2 dlg = new Form2();
dlg.Show();
}
如何为此更改此代码?谢谢大家。
我从 Form1 创建 Form2。我希望 Form2 在第二台显示器上打开。我怎么能做到这一点?我使用这段代码:
private void button1_Click(object sender, EventArgs e)
{
Form2 dlg = new Form2();
dlg.Show();
}
如何为此更改此代码?谢谢大家。
使用此代码
Form2 dlg = new Form2();
Screen[] screens = Screen.AllScreens;
Rectangle bounds = screen[1].Bounds;
dlg.SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height);
dlg.StartPosition = FormStartPosition.Manual;
dlg.Show();
尝试这样的事情
Screen[] sc;
sc = Screen.AllScreens;
//get all the screen width and heights
Form2 f = new Form2();
f.FormBorderStyle = FormBorderStyle.None;
f.Left = sc[neededmonitor].Bounds.Width;
f.Top = sc[neededmonitor].Bounds.Height;
f.StartPosition = FormStartPosition.Manual;
f.Show();
您可以像这样检测辅助监视器(使用 System.Linq):
var screen = Screen.AllScreens.FirstOrDefault(s => !s.Primary && s.DeviceName.Contains("DISPLAY2"));