0

I have a windows application where, When i click a button on Form1 opens Form2. I have a aone more button on Form2 when i click that it suppose to open Form1.

Form 1 :
     Form form2 = new Form2();
     form2 .ShowDialog();
     Form1.Close();
Form 2 : 

     Form form1 = new Form1();
     form1.ShowDialog();
     form2.Close();

The Application ends..Can anyone explain how to achieve rectify this?

Spider man
  • 3,224
  • 4
  • 30
  • 42
Bharani
  • 97
  • 11

1 Answers1

0

Assuming Form1.Close() is a typo: You can not close the parent form of an application. Once this window closes, the application closes.

With WPF you could do otherwise:

Application.ShutdownMode = ShutdownMode.OnLastWindowClose;

See: Windows Forms: Change application mainwindow at runtime

Community
  • 1
  • 1
Mario The Spoon
  • 4,799
  • 1
  • 24
  • 36