小编典典

在辅助监视器上显示Windows窗体?

c#

我试图在辅助监视器上设置Windows窗体,如下所示:

private void button1_Click(object sender, EventArgs e)
{
    MatrixView n = new MatrixView();
    Screen[] screens = Screen.AllScreens;
    setFormLocation(n, screens[1]);
    n.Show();
}

private void setFormLocation(Form form, Screen screen)
{
    // first method
    Rectangle bounds = screen.Bounds;
    form.SetBounds(bounds.X, bounds.Y, bounds.Width, bounds.Height);

    // second method
    //Point location = screen.Bounds.Location;
    //Size size = screen.Bounds.Size;

    //form.Left = location.X;
    //form.Top = location.Y;
    //form.Width = size.Width;
    //form.Height = size.Height;
}

边界的属性似乎是正确的,但是在我尝试过的两种方法中,这都会最大化主监视器上的形式。有任何想法吗?


阅读 223

收藏
2020-05-19

共1个答案

小编典典

尝试将StartPosition参数设置为方法FormStartPosition.Manual内部SetFormLocation

2020-05-19