单例模式创建窗口

Parent.cs:

Child child = Child.ChildSignleton();
child.MdiParent = this;
child.Show();

Child.cs:

public static Child childform = null;
public static Child ChildSignleton()
{
    if (childform == null)
    {
        childform = new Child();
    }
    return childform;
}

private void Child_FormClosing(object sender, FormClosingEventArgs e)
{
    try
    {
        this.Dispose(true);
        childform = null;
    }
    catch (Exception m)
    {
        MessageBox.Show(m.ToString());
    }
}
posted @ 2018-12-20 16:54  Kyle0418  阅读(295)  评论(0编辑  收藏  举报