Results 1 to 3 of 3

Thread: How to call sub in MDI child form from MDI parent toolbar?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2010
    Posts
    478

    How to call sub in MDI child form from MDI parent toolbar?

    I created a few toolbars in parent form.
    How to call sub in MDI child form from MDI parent toolbar?

  2. #2
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,398

    Re: How to call sub in MDI child form from MDI parent toolbar?

    The MDI parent will need to hold a reference to the created child.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: How to call sub in MDI child form from MDI parent toolbar?

    There are a few ways that you can handle this. As ident says, 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width