MDI Form detecting with a child form is added or removed

前端 未结 8 797
心在旅途
心在旅途 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

    Wire up the MdiChildActivate event and keep a list of recognized children. When a new form is activated, also wire up the FormClosed event.

    private List
    ChildFormList = new List(); private void MyForm_MdiChildActivate(object sender, EventArgs e) { Form f = this.ActiveMdiChild; if (f == null) { //the last child form was just closed return; } if (!ChildFormList.Contains(f)) { //a new child form was created ChildFormList.Add(f); f.FormClosed += new FormClosedEventHandler(ChildFormClosed); } else { //activated existing form } } private void ChildFormClosed(object sender, FormClosedEventArgs e) { //a child form was closed Form f = (Form)sender; ChildFormList.Remove(f); }

提交回复
热议问题