toolstrip containing a list of mdi children
Hi all,
I'm working on a project with a big number of forms. I'm using an MDI container as my main screen, with a menu and everything, so I can open MDI childs in it.
I inserted a Toolstrip docked at the bottom of the mdi parent, because I had this great idea to show all open mdi children in this toolstrip. Each childform would have it's own ToolStripButton, and the child form which is activated at that time, would be highlighted in the toolstrip. This way, users can see which childs are opened and switch between child forms without having to open the 'window' menu (the one on MdiWindowListItem). I can easily iterate through the MdiChildren list, get some properties, and create the buttons.
So, I started building the code to set this up, but then I hit some problems already. I want the toolstrip to update itself as soon as forms are opened or closed.
- My first idea was to use the MdiChildActivate event on the mdi parent, and build the toolstrip from here everytime it's fired. It's fired whenever an mdi is activated, or closed. Although this almost sounds exactly what I need, I don't want to rebuild it whenever a user switches between two child forms (still fires because of 'activated'). Also, when a child form is closed, the event is fired before it's removed from the MdiChildren list, so it doesn't remove my toolstripbutton at all until it fires again.
- I thought using my own functions would suffice. I created an AddChild(Form child) function, inserted a random number into child.Tag, added an event on FormClosed, and created a ToolStripButton with the same tag. When the child form would close, it would fire the FormClosed event, and then I could easily find the right ToolStripButton with the tag. It was anything but easy, and it still doesn't work. Also, I don't think this is the way to go, because I have tons of child forms, which can create other child forms as well, which need their own functions (+ formclosed event) added as well. I think this is a bit too much for something this simple.
Isn't there a better way to check if child forms are opened or closed from the MdiParent? Something like MdiChildrenListChanged or anything like it?