【问题标题】:Best way to open main app from main menu in winforms从winforms的主菜单打开主应用程序的最佳方式
【发布时间】:2021-01-31 09:38:00
【问题描述】:

我最近开始学习winforms,我想制作一个带有开始按钮的主菜单,这样当我点击按钮时,它会显示下一个屏幕(我很难正确地表达出来)。 我试过使用

            frm2.Show();
            frm2.Left = this.Left;
            frm2.Top = this.Top;
            frm2.Size = this.Size;
            this.Hide();

但问题是,当第二个表单打开时,会出现一个打开的小动画,还有一个关闭主表单的小动画,因此看起来并不无缝。也许最好在单击按钮时重新排列表单的布局?最好的实现是什么?

【问题讨论】:

  • “下一个屏幕”是指另一种形式吗?因此,您希望在第一个表单中按下按钮时显示第二个表单。这个对吗?请说明您是要以模态方式打开(像对话框一样阻止第一个表单)、并排打开还是代替第一个表单。

标签: c# winforms


【解决方案1】:

我认为这是你想要的行为

private void button1_Click(object sender, EventArgs e)
{
    var next = new Form2();           // Create the next form
    next.StartPosition = FormStartPosition.Manual;
    next.Location = this.Location;    // Assign size/location
    next.Size = this.Size;
    this.Visible = false;             // Hide this form
    next.ShowDialog();                // Show next form, pausing this code here
    this.Visible = true;              // Resume code once next form is closed.
}

一些屏幕截图。

点击前

点击后

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多