我在直接关闭子窗体事件里面加了e.cancel =true;实现最小化处理,现在想如何实现在关闭主窗体时把这个子窗体也关闭,因为上面的写法导致了子窗体关闭不了。

解决方案 »

  1.   

    加个属性
    if(父窗要你关闭)
    {
        e.cancel =false;    
    }
      

  2.   

    在Closing事件里面的e有个Reson属性
    你可以通过这个属性来区分当前请求的关闭命令
    或者设置变量通过父窗体关闭为true,否则为false
    然后在closing的时候判断这个变量
      

  3.   

    在子窗体中设置一个全局静态的bool变量
    public static IsClose=fales;在子窗体的直接关闭子窗体事件中:
    if(!IsClose)
      e.cancel =true;
    else 
      e.Cancel=fales ;
    在主窗体的关闭窗体事件中:FrmCh.IsClose=true;
      

  4.   

    //关闭窗体
    this.Close();
    //退出整个应用程序
    Application.Exit();
      

  5.   

    可以通过判定 e.CloseReason 来区分关闭Form的动作是由用户发出的还是系统发出的
    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
    if (e.CloseReason == CloseReason.UserClosing)
    {
    e.Cancel = true;
    }
    }
      

  6.   

    press power key for 5 seconds,a joke