如何在第二台显示器上打开form2?

时间:2012-05-24 07:39:07

标签: c#

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

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

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

3 个答案:

答案 0 :(得分: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();

答案 1 :(得分: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(); 

答案 2 :(得分:0)

您可以检测辅助监视器(使用System.Linq),如下所示:

var screen = Screen.AllScreens.FirstOrDefault(s => !s.Primary && s.DeviceName.Contains("DISPLAY2"));