在另一种形式上打开新形式

Opening new form over another form

我的主窗体有几个按钮,每个按钮都会打开新窗体。当我单击 button1 时,form1 打开,当我单击 button2 时,form2 打开但 form1 返回到主窗体。我想要这样的功能,即每个新表单都在父表单上打开,而最新的表单在顶部。

这是我的代码

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

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

    private void button3_Click(object sender, EventArgs e)
    {
        Form3 form = new Form3();
        form.Show();
    }

每个表单都有一个最顶层的属性,只需将它们设置为true

private void button1_Click(object sender, EventArgs e)
    {
        Form1 form = new Form1();
        form.Show();
        form.TopMost = true;
        form.Activate();
    }

    private void button2_Click(object sender, EventArgs e)
    {
        Form2 form = new Form2();
        form.Show();
        form.TopMost = true;
        form.Activate();
    }

    private void button3_Click(object sender, EventArgs e)
    {
        Form3 form = new Form3();
        form.Show();
        form.TopMost = true;
        form.Activate();
    }