0

I've had a look around but none of the answers make any sense to me. I have a menu form which has buttons on; when users come to use the menu form, you can open other forms from the menu. Currently, I can get the form to open, but the menu form stays open too.

private void BtnAddNewCar_Click(object sender, EventArgs e)
{
AddCompanyCar carForm = new AddCompanyCar();
carForm.ShowDialog();
}

The code above opens the form AddCompanyCar from the menu. How do I add to this code so that the form 'Menu' closes when AddCompanyCar opens?

Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215

3 Answers3

0

Are you sure want to do this as it impacts usability. If you're using WinForms, then just create a container window, and replace the panels instead. Might be easy and best way

If not and you wanna go-ahead, can take a look on this example

A.K
  • 320
  • 5
  • 14
0

Why not just hide it, then show it again when ShowDialog() returns?

private void BtnAddNewCar_Click(object sender, EventArgs e)
{
    this.Visible = false;

    AddCompanyCar carForm = new AddCompanyCar();
    carForm.ShowDialog(); // execution stops here until "carForm" is dismissed

    this.Visible = true;
}
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40
0

by closing the main window, you destroy the context in which you were previously working. As others suggest, simply hide the main window so you can return to it.

M. Vogel
  • 25
  • 5