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

So far, this is the button click event to instantiate the other form of the button. It pops up the other form—but the first form is still in the background, and after closing the second one, the first also closes and stops running. Any advice?

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


Solution 1:[1]

Your code seems to (unintentionally) stop at the .ShowDialog() line:

// 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();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1