Tzu Chi Learning, technology is willing to learn. Good heart to create a lot of Masarica, after the shade. I write the experience today, I would like to see the text to enlighten.
1, the wrong code Form1
Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Windows.Forms;
Namespace WindowsFormsApplication4
{public
partial class Form1:form
{public
Form1 ()
{
InitializeComponent ();
}
private void Button1_Click (object sender, EventArgs e)
{
Form2 frm2 = new Form2 ();
Frm2. Show ();}}
Form2
Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Windows.Forms;
Namespace WindowsFormsApplication4
{public
partial class Form2:form
{public
Form2 ()
{
InitializeComponent ();}}
Effect
2, improve the code
Form1
Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Windows.Forms;
Namespace WindowsFormsApplication4
{public
partial class Form1:form
{public
Form1 ()
{
InitializeComponent ();
}
private void Button1_Click (object sender, EventArgs e)
{
Form2 frm2 = Form2.form2single ();
Frm2. Show ();}}
Form2
Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Threading.Tasks;
Using System.Windows.Forms;
Namespace WindowsFormsApplication4
{public
partial class Form2:form
{
private Form2 ()
{
InitializeComponent ();
}
private static Form2 Form2 = null;
public static Form2 Form2single ()
{
if (form2==null)
{
Form2 = new Form2 ();
}
return Form2;
}
}
The right effect
2017-11-29
This is the design pattern of a single case pattern, design patterns belong to the realm of Zen, beginners to this will be good, do not do too high requirements. You can buy a book and learn it.
Thanksgiving has helped the heart of the less park people.
C # is excellent and worth learning. WINFORM,WPF can be concerned about, broaden their horizons. The
Visual Studio IDE is very handy, recommended.
Note: This article is born of self-study notes, the quality of the lower, so think twice before you do. Novice to this, can not be copied, should first study its image number, to be able to adapt when the natural jump out of deep pits.