Recently I am working on a winform application.ProgramWhen the MDI form is used, a lot of trouble is encountered. One of them is how to solve the problem of not letting the child form be instantiated multiple times.
I have searched the internet for a long time and found many solutions. Here I will introduce some simple methods.
In fact, this is the singleton mode in the classic 23 design patterns. The following uses C # To implement it:
Suppose we have two winforms. The main form is mainform and the child form is childform.
Add a button1 in the main form to instantiate the child form.Code:
Private Static childform; // static variable to save the unique instance
Private void button#click (Object sender, system. eventargs E)
{
If (childform = NULL | childform. isdisposed)
{// If the first instantiation or instantiation form is disabled, it must be re-instantiated.
Childform = new childform ();
Childform. mdiparent = this;
Childform. Show (); // display
}
}
Bytes ----------------------------------------------------------------------------------------------------------
The above code has been run in vs2008 (C #), and my personal abilities are limited. I hope you can give me some advice!