locked
How to reuse MenuStrip in another form RRS feed

  • Question

  • HI,

    I m new  to VB. I have created a form with Menustrip and want to reuse this menustrip in other forms. Could anyone plz tell me how to do it ?

    Thursday, July 22, 2010 9:46 PM

Answers

  • HI,

    I m new  to VB. I have created a form with Menustrip and want to reuse this menustrip in other forms. Could anyone plz tell me how to do it ?


    Use the MeunStrip on 1 form in conjunction with a TabControl.  When have a need for a new form, just add a new TabPage and design things on it as you would on a Form.  Doing it this way will give you access to your MenuStrip anytime you need it.

    :)


    Doug

    SEARCH ... then ask
    • Proposed as answer by Cabe O Friday, July 23, 2010 2:37 PM
    • Marked as answer by Marc.Gauthier Friday, July 23, 2010 6:00 PM
    Thursday, July 22, 2010 11:29 PM

All replies

  • I am not sure if this is possible, you may have to just make a new one on all forms.

    try clicking the Menustrip Icon at the bottom of the screen and copying that one , then select your next form and paste it...

    let me know if it works

    thanks

    Thursday, July 22, 2010 10:26 PM
  • HI,

    I m new  to VB. I have created a form with Menustrip and want to reuse this menustrip in other forms. Could anyone plz tell me how to do it ?


    Use the MeunStrip on 1 form in conjunction with a TabControl.  When have a need for a new form, just add a new TabPage and design things on it as you would on a Form.  Doing it this way will give you access to your MenuStrip anytime you need it.

    :)


    Doug

    SEARCH ... then ask
    • Proposed as answer by Cabe O Friday, July 23, 2010 2:37 PM
    • Marked as answer by Marc.Gauthier Friday, July 23, 2010 6:00 PM
    Thursday, July 22, 2010 11:29 PM
  • couldn't you just pass the menustrip to the other Form's constructor when you call the new instance of the second Form?

    on Form2 declare it WithEvents so you can access the events for it (such as ItemClicked) , and in the Form's constructor set the Form's menstrip to the passed menustrip

    then in the Form2 Load event add it to the Form's Control collection.

    Friday, July 23, 2010 12:09 AM
  • Marc,

    I've never seen a VB application with two independent forms which could use their own menustrips.

    Or you should use a MDI application.

    For an MDI application there is a special way, to use the same menus on the different forms.

    Are you using that?

    In a Windows application there is one messagepump (the way events are sent to the application) which goes only to one form.

     


    Success
    Cor
    Friday, July 23, 2010 6:39 AM
  • Well you could put the strip in a common module and at the correct time, populate the toolbar with form appropriate items.

    Renee

    Friday, July 23, 2010 7:38 AM
  • You can create a base form class with the menustrip (and other common controls), and then have your individual window forms inherit from it.
    Friday, July 23, 2010 3:48 PM
  • Try this:

    Add a class to your project called MyMenuStrip

    Make the first statement in the class:  Inherits MenuStrip

    Now, rebuild your MenuStrip, removing code from your project as you add the code to your MyMenuStrip class.

    Finally remove the original MenuStrip from the project and build the solution.  Your MyMenuStrip will appear at the top  of the ToolBox.  Add it to your form and build your solution.  You should be back  to where you started, but with a reusable menustrip.

     

    Friday, July 23, 2010 4:50 PM
  • I tried with TabControl and it works. Thanks a lot.
    Friday, July 23, 2010 6:02 PM