繁体   English   中英

Visual Studio C#在同一窗口中打开表单

[英]Visual Studio C# Opening forms in the same window

对于可能引起误解的标题,我感到很抱歉,但是我想不出更好的办法了。 因此,我想创建一个应用程序,在该应用程序中,当按下按钮时,它会打开另一个表单,但是它将替换原始表单。 我需要许多其他程序具有的功能。 它只是将表单中的数据替换为第二个表单数据。 第二种形式将与前一种形式相同,只是其他内容相同-位置相同,大小相同。所有内容都应相同。 对不起,我的英语不好,谢谢您的阅读。

我不知道您为什么要编写此程序,我想为您提供以下代码。

private void button1_Click(object sender, EventArgs e)
{
    // #1. Make second form
    // If you want to make equivalent one, then change Form2 -> Form1
    Form2 form2 = new Form2();

    // #2. Set second form's size
    form2.Width = this.Width;
    form2.Height = this.Height;

    // #3. Set second form's start position as same as parent form
    form2.StartPosition = FormStartPosition.Manual;
    form2.Location = new Point(this.Location.X, this.Location.Y);

    // #4. Set parent form's visible to false
    this.Visible = false;

    // #5. Open second dialog
    form2.ShowDialog();

    // #6. Set parent form's visible to true
    this.Visible = true;
}

好的,所以我终于可以在面板上使用它了。 我的解释能力很差。 无论如何,谢谢您的时间!

在您的项目上,单击添加,然后用户控件,然后添加新表单

在您的代码上按下botton时添加

Form2 form = new Form2();
                form.ShowDialog();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM