能不能阻止同一个窗体被同时打开多次呢?

解决方案 »

  1.   

    还可以这样
    在窗体中加入如下代码
    private static 窗体 instance = null;
    //添加一个属性
    public static 窗体 Instance
    {
         set{
         }
         get{
             if(instance == null){
                 new 窗体();
             }
             return instance;
         }
    }在窗体的构造函数中加入如下代码
    instance = this;创建窗体Closed事件
    private void 窗体_FormClosed(object sender, FormClosedEventArgs e)
    {
        instance = null;
    }
    使用方法:
    在要调用该窗体的地方加入如下代码
    窗体 myfrm = 窗体.Instance; 
    myfrm.Show();
    myfrm.Activate();
      

  2.   

    1:单例模式
    例如楼上2:以模态对话框的形式打开
    窗体.ShowDialog();3.把被打开窗体定义在本窗体类外部。
      

  3.   

    showdialog
    或者用判断是否显示咯。