窗体单例

using System.Windows.Forms;

namespace Keleyi.Com
{
public partial class AboutForm : Form
{
private static AboutForm _instance;

private AboutForm()
{
InitializeComponent();
}

private void AboutForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason== CloseReason.UserClosing)
{
this.Hide();
e.Cancel = true;
}
}

public static AboutForm GetInstance()
{
if (_instance == null)
_instance = new AboutForm();

return _instance;
}
}
}
构造函数私有化,声明静态窗体变量
在父容器中调用子窗体的getInstance方法,获得aboutForm对象

 

posted @ 2016-02-02 20:22  wxl_yq  阅读(213)  评论(0编辑  收藏  举报