关闭 C# 中的第一个窗体以显示第二个窗体,但在关闭第二个窗体后,第一个窗体返回

Closing the first form in C# to show the second, but after closing the second the first comes back

至此,这是实例化按钮的另一种形式的按钮点击事件。它弹出另一个窗体——但第一个窗体仍在后台,关闭第二个窗体后,第一个窗体也关闭并停止运行。有什么建议吗?

private void BtnInventoryClickEvent(object sender, EventArgs e)
    {
        frmInv viewInve = new frmInv();
        viewInve.ShowDialog();
        this.Hide();
    }

您的代码似乎(无意中)停在 .ShowDialog() 行:

// your first line:
        frmInv viewInve = new frmInv(); // here the new frmInv is getting created successfully
        viewInve.ShowDialog(); // but here the code would stop
// because ShowDialog() produces a so called "modal window", AKA "dialog"
// so that the next line does not run before the current user would 
// interactively close frmInv.
// And then the next line hides your current Form:
        this.Hide();