2

我正在编写一个简单的 Windows 窗体应用程序。我希望表单仅在主屏幕中打开,无论在哪个屏幕中调用应用程序(假设用户有多个屏幕)。主屏幕的目的是用于显示 Windows 任务栏的屏幕。

谢谢,毛尔。

4

2 回答 2

4

你可以试试这个:

/// <summary>
/// Sets the location of the form to primary screen.
/// </summary>
/// <param name="this">Instance of the form.</param>
/// <param name="x">The x coordinate of the form's location.</param>
/// <param name="y">The y coordinate of the form's location.</param>
public static void SetPrimaryLocation(this Form @this, int x = 0, int y = 0)
{
    var rect = Screen.PrimaryScreen.WorkingArea;
    @this.Location = new Point(rect.X + x, rect.Y + y);
}
于 2018-07-20T12:15:06.413 回答
-1

您应该将主窗体的 IsMdiParent 属性设置为 yes。

当你展示其他表格时,你应该像这样展示它们:

    private void MainForm_Load(object sender, EventArgs e)
    {
        Form2 frm = new Form2();
        frm.MdiParent = this;
        frm.Show();
    }

这将在您的主窗体中打开 Form2。

于 2018-07-20T12:36:20.203 回答