Click here to Skip to main content
15,914,390 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi now i m working on window base program but i need a help.when i open a window from menu when i click on that menu again then i got that window that is already open in c#
Posted
Updated 17-Sep-11 0:45am
v3
Comments
Tejas Vaishnav 17-Sep-11 6:47am    
Hello friend Please Rate My Ans if you like it

You need to store the from instance as a class level variable. When you run the menu handler, check if the variable is null and only open the new window if it is. Then store the new form instance in the variable for later.
You will also want to handle the form FormClosed event to return the saved instance to null.
 
Share this answer
 
Comments
prakash00060 17-Sep-11 6:29am    
can you give me any example sir
You have to create a class or file where all the global variables have been declared and that file or class has been assessed in whole application
your all child form will be declared there.
C#
public class GlobalVar
{
    private static MyChildForm _My;
    public MyChildForm MyChild
    {
        get
        {
             if(_my == null)
             {
                 _my = new MyChildForm();
                 return _my; 
              }
             else
             {
                 return _my;
             }
         }
    }
}


now in your menu item click event write this code

C#
GlobalVar glob = new GlobalVar();

private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
      glob.MyChild.Show();
}
 
Share this answer
 

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