Call sub in MDI child form from MDI parent toolbar

aspfun

Active member
Joined
Feb 16, 2010
Messages
34
Programming Experience
5-10
I created a few toolbars in parent form.
How to call sub in MDI child form from MDI parent toolbar?
 
There are a few ways that you can handle this. If the parent form wants to affect the child form then it must have a reference to it, which goes for all objects. You could declare a member variable and assign the child form to it when you create it and then always use that variable. Alternatively, you can use the MdiChildren property, which is a collection of all the child forms. You can use a loop or a LINQ query to get the desired child by appropriate criteria.

There is another alternative though, which is the "professional" way to use MDI. Instead of creating the tool bar in the parent form, you create in the child form. That way, all the code goes in the child. You then use the merging functionality of the ToolStrip class to make the tool bar appear in the parent at run time. As far as the user is concerned, the tool bar is part of the parent but, as far as the code is concerned, it's part of the child. You get the best of both worlds.
 
Back
Top