Sunday, April 25, 2010

Creating Single instance of a windows Form

//Following Code in Child form Class 
//creating form's object.
public static volatile System_Categorization singleObj;

        
// Function in the Form
public static System_Categorization singleInstance()
 {
 if (singleObj == null)
  {
    lock (typeof(System_Categorization))
     {
       if (singleObj == null)
        {
          singleObj = new System_Categorization();
        }
     }
  }
return singleObj;
}

//On Disposing please Please Write following code in Designer class 

protected override void Dispose(bool disposing)
 {
   //mainform objmainform = new mainform();
            
     if (disposing && (components != null))
       {
         components.Dispose();
       }
       base.Dispose(disposing);
     singleObj = null;
           
 }
 
//Following Code in Parent form Class 
// Now open the form as write code in Parent Form
 
 //System_Categorization objForm = new System_Categorization();
System_Categorization.singleInstance().Show(); 

16 comments:

  1. <a href="https://alfahad-almotamayez.com/%d8%b4%d8%b1%d9%83%d8%a9-%d8%aa%d8%b3%d9

    ReplyDelete