Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am working on windows base c# project; i have taken a menu strip and added menu name. While click on a particular menu desired form is opening.
Now i want to do one thing that while someone has opened one form until the form is closed they cannot open another form. So that means after closing that particular form they can access other form.
Can anyone please guide me how can i do this?

Thanks in advance
Posted

Hi,

On Menu Item Click event add below Code,

C#
if(Application.OpenForms.Count > 0)
{
   bool flag = false;
   foreach(Form frm in Application.OpenForms)
   {
      if(frm.Name == "frmMenu")
      {
          //Ignoring the MDI form or the form with menu
      }
      else
      {
          flag = true;
          break;
      }
   }

   if(flag)
   {
       MessageBox.Show("Kindly close the current Form");
   }
   else
   {
      Form2 frm = new Form2();
      frm.Show();
      //Open the new form
   }
}
else
{
   Form2 frm = new Form2();
      frm.Show();
      //Open the new form
}


hope it helps.
 
Share this answer
 
Comments
sariqkhan 29-Sep-12 0:43am    
+5
Karthik Harve 29-Sep-12 0:47am    
Thanks !!!
windowsform1 f1=new windowsform1();
f1.showdialog();

Check this.
 
Share this answer
 
form1 f1= new form1();
f1.showdialog();
use this
 
Share this answer
 
Comments
sahabiswarup 29-Sep-12 0:34am    
Thanks a lot..
sariqkhan 29-Sep-12 0:42am    
your welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900