//C# WinForm 单例模式(例:同一个窗体只创建一次实例)
//打开窗体的事件: Form3 f = Form3.InstanceObject() ; //实例化窗体
f.Focus(); //让窗体获得焦点
f.Show(); //显示窗体 //被打开的窗体: public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
} private static Form3 _instance; //创建窗体对象的静态方法
public static Form3 InstanceObject()
{
if (_instance == null)
_instance = new Form3();
return _instance;
} //窗体关闭事件
private void Form3_FormClosing(object sender, FormClosingEventArgs e)
{
_instance = null;
}
}