菜单项按钮弹出子窗口后按钮enabled=false,子窗口关闭后按钮enabled=true;父窗口和子窗口各为不同的两个窗口类。弹出子窗口写法是:
frmB chidfrmB=new frmB();
chidfrmB.MdiParent=this;
chidfrmB.show();
问题是如何获得子窗口关闭后的状态让菜单按钮重新有效?-----------------------------------------------------
思路1:(主窗口判断子窗口全关闭)
if(this.MdiChildren   ==null)  判断这个数组是否为空就可以了
或者this.MdiChildren.Count==0也可以有问题:如何触发这个事件呢??-----------------------------------------------------
思路2:(子窗口关闭时触发)
//放到初始化中
this.Closing += new CancelEventHandler(this.whoisresult_Cancel);//放到事件中
        protected void newForm_Closing(object sender, CancelEventArgs e)
        {
            MessageBox.Show("关闭");
        }有问题:测试过可以show出“关闭”,但是如何传递给主窗口去触发事件去改变按钮enabled值呢?
----------------------------------------------------

解决方案 »

  1.   

    不要放到初始化中this.Closing += new CancelEventHandler(this.whoisresult_Cancel);
    在主窗体中new的时候
    frmB chidfrmB=new frmB();
    chidfrmB.MdiParent=this;
    chidfrmB.Closing += new CancelEventHandler(this.whoisresult_Cancel);
    chidfrmB.show();
    ,chidfrmB关闭的时候就会出发主窗口中的whoisresult_Cancel
      

  2.   

    to
     ufoteam(帅哥!问题解决了就应该结贴!不结贴后果是信誉降低!) 
    -------------------------------------------------------------------
    跟思路2一样嘛whoisresult_Cancel是子窗口的事件!
    但是如何传递给主窗口去触发事件去改变主窗口按钮enabled值呢?
    又或者如何在子窗口中操作改变主窗口按钮enabled值呢?
      

  3.   

    使用ufoteam(帅哥!问题解决了就应该结贴!不结贴后果是信誉降低!) ( )的方法
    在whoisresult_Cancel判断关闭窗口的Name属性,改变主窗体的按钮。private void whoisresult_Cancel(object sender , CancelEventArgs e)
    {
       Form closedChildForm = sender as Form;
      
       switch(closedChildForm.Name)
      {
         case "XXX1" : //按钮处理1
                  return;
         case "XXX2"://按钮处理12
                  return;
           .....
         
       }
    }
      

  4.   

    private void MDIParent1_MdiChildActivate(object sender, EventArgs e)
            {
                  //YOUR CODE
            }