希望我的描述比较清楚.  SmartTimers smartTimers = new SmartTimers();
  smartTimers.MdiParent = this;
  smartTimers.Show();
//SmartTimers窗口的
 private void SmartTimers_FormClosing(object sender, FormClosingEventArgs e)
 {
     e.Cancel = true;
     this.WindowState = FormWindowState.Minimized;
 }
这样,比较痛苦的问题就来了,我想关闭MDI窗口,应该怎么关闭呢?
请各位有过这样问题的朋友帮个忙.

解决方案 »

  1.   

    设置一个静态公共变量,初始值为false
    关闭子窗口时,判断该变量的状态,false为不关闭
    要关闭MDI时,设置为true  SmartTimers smartTimers = new SmartTimers();
      smartTimers.MdiParent = this;
      smartTimers.Show();
    //SmartTimers窗口的
     private void SmartTimers_FormClosing(object sender, FormClosingEventArgs e)
     {
         e.Cancel = Common.IsMDIExit;//Common.IsMDIExit为静态公共变量
         this.WindowState = FormWindowState.Minimized;
     }
      

  2.   

    回1L,是winform...
    冒昧的问2L一下,除了设置标志变量的办法,再没有什么更好的方法了吗?
      

  3.   

    .net 1.1的时候,直接Application.Exit()也行,但.net 2.0就不可以了。你这样捕获取消关闭事件,可扩展性太差,暂时没想到更好的办法
      

  4.   

    Common.IsMDIExit
    还是遇到问题了...Sorry,问题太多...设置标志变量还有是一点点问题.子窗体是在MDI窗体之前触发closing事件...也就是说,如果要MDI窗体将IsMDIExit设置为true的时候,子窗体要先执行一次..private void SmartTimers_FormClosing(object sender, FormClosingEventArgs e)
    {
         if (!(PublicInfo.IsMDIExit)) // 这里首先被执行,然后MDI窗体的PublicInfo.IsMDIExit = true 才被执行.
         {
             e.Cancel = true;
             this.WindowState = FormWindowState.Minimized;
         }
    }
    导致的结果就是,需要点击两次关闭,整个MDI窗口才会关闭.刚刚接触WINFORM编程,所以有许多不太明白的地方,还请多帮忙啊.
      

  5.   

    可以在MDI关闭时捕捉事件设置后再紧跟这一个this.Close();
      

  6.   

            ' Close all child forms of the parent.
            For Each ChildForm As Form In Me.MdiChildren
                ChildForm.Close()
            Next
      

  7.   

     if (e.CloseReason != CloseReason.MdiFormClosing && e.CloseReason != CloseReason.ApplicationExitCall)
                {
    e.Cancel = true;
             this.WindowState = FormWindowState.Minimized;
    }