3

我从 Form1 创建 Form2。我希望 Form2 在第二台显示器上打开。我怎么能做到这一点?我使用这段代码:

private void button1_Click(object sender, EventArgs e)
{
    Form2 dlg = new Form2();
    dlg.Show();
}

如何为此更改此代码?谢谢大家。

4

3 回答 3

8

使用此代码

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();
于 2012-05-24T07:44:47.647 回答
3

尝试这样的事情

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(); 
于 2012-05-24T07:46:32.380 回答
0

您可以像这样检测辅助监视器(使用 System.Linq):

var screen = Screen.AllScreens.FirstOrDefault(s => !s.Primary && s.DeviceName.Contains("DISPLAY2"));
于 2017-08-01T07:52:21.137 回答