Is there an event I can use to tell if a child form has been added or removed from the MDI parent?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Wire up the
MdiChildActivate
event and keep a list of recognized children. When a new form is activated, also wire up theFormClosed
event.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.
No, there is not. You would have to subclass Form and expose specific events that would indicate when the child is added and then route all attachments of child forms through a method that would wire up the child form, as well as raise the event.
Since the MdiChildActivate event is fired before the MDI child form is actually closed and therefore there isn't enough information to detect if a MDI child form is actually activated or closed, I chose a different approach to solve the problem.
I found that the ParentChanged event fires on the MDI child form when it is closed.
I realised this is many years too late however as the answers here helped me solve this I though I would mention this works fine using the MdiChildren array in .net 4. The only thing you need to do is check if the form is disposing or disposed to tell if its closing.
ie: