第一种解决方法 “单例”
form1
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = Form2.GetInstance();
f2.Show();
}
form2
public partial class Form2 : Form
{
private static Form2 instance;
private static object _lock = new object();
private Form2()
{
InitializeComponent();
}
public static Form2 GetInstance()
{
if (instance == null || instance.IsDisposed)
{
lock (_lock)
{
if (instance == null || instance.IsDisposed)
{
instance = new Form2();
}
}
}
return instance;
}
}