MDI Form detecting with a child form is added or removed

前端 未结 8 787
心在旅途
心在旅途 2020-12-21 08:11

Is there an event I can use to tell if a child form has been added or removed from the MDI parent?

8条回答
  •  不思量自难忘°
    2020-12-21 08:34

    I recently wanted to determine approximately when there were NO MDIchildren open so I could display a panel with lots of "things to do" buttons on it Only when there were no child forms open. (just exploring a design idea).

    My eventual solution was elegantly simple - add a timer to the parent form and start the timer up whenever the MdiChildActivate event determined there was 1 child form open.

        private void MyForm_MdiChildActivate(object sender, EventArgs e)
        {
            this.panel_Tools.Visible = false;
            if (this.MdiChildren.Count() == 1)
            {
                this.timer_WindowsCounter.Start();
            }
            else
            {
                this.timer_WindowsCounter.Stop();
            }
    
        }
    
    
        private void timer_WindowsCounter_Tick(object sender, EventArgs e)
        {
            if (this.MdiChildren.Count() == 0)
            {
                this.panel_Tools.Visible = true;
                this.timer_WindowsCounter.Stop();
            }
        }
    

提交回复
热议问题