Reputation: 3912
Is there a simple way of tracking the change of an Mdi's children i.e. when they are created and closed, something like an event OnMdiChildListChanged (I realise this doesn't actually exist).
I am also aware that I could have a method within my Mdi that handles the creation of child forms and logs the state of them or even create an Interface that defines that a child form has a "NotifyParent" method that is then called on close of the form, but i was wondering if there was any built in events that i could plumb into?
Upvotes: 1
Views: 1924
Reputation: 942119
This plumbing already exists, it is used to automatically update the MDI window list (MenuStrip.MdiWindowListItem property). The Form class has code in the OnVisibleChanged and OnMdiChildActivate methods to update the menu. Idle hope though, You can't see the menu item list change, nor can you override any of the plumbing code. Not without doing similar and overloading these methods in your own child forms.
Punt this problem, simply write a public method in your MDI parent form that you consistently use to add new child windows:
public void AddChild(Form child) {
child.MdiParent = this;
child.FormClosed += child_FormClosed;
// Run your code to handle new child windows here...
}
private void child_FormClosed(object sender, FormClosedEventArgs e) {
// Your code to handle closed child windows here...
}
You can even make AddChild static, since there's only ever one MDI parent.
Upvotes: 1
Reputation: 3183
MdiChildActivate (or OnMdiChildActivate) will fire when a Mdi child is opened or closed.
Upvotes: 1
Reputation: 52952
You could create your own event, and fire it in the associated methods yourself. It's fairly simple, and you can subscribe to it just like a built in event.
Upvotes: 0