winforms - Avoid duplicate form loading in c# -


i have 2 windows forms.both form1 , form2 have button. when click button in form1 shows form2 , vice versa. create duplicate form when click button on each time. how avoid it. please tell me. code given below.

form1:

private void button1_click(object sender, eventargs e) {     form2 f2 = new form2();     f2.show(); } 

form2:

private void button1_click(object sender, eventargs e) {     form1 f1 = new form1();     f1.show(); } 

just use method common , pass parameter 'this' when button click

 public bool formisexist(form frmopen)     {         formcollection fc = application.openforms;          foreach (form frm in fc)         {             if (frm.name == frmopen.name)             {                return true;             }         }          return false;     } 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -