Custom Main Menu control

bpl

Member
Joined
Jun 3, 2004
Messages
7
Programming Experience
10+
I have a number of forms with almost identical menus. I want to create a Main Menu that has the common items on it, and then copy and paste the control to other forms. How can I implement it?
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
Here's where the power of OOP (Object-oriented programming) comes in.
You can create a "template" form that contains the MainMenu with the common MenuItems. Set the scope of the MainMenu control (Modifiers property) to public; this allows you to modify it on the other forms.
Then have the other forms inherit that form. To do that, change the line:
VB.NET:
Inherits System.Windows.Forms.Form
to
VB.NET:
Inherits RootNamespace.TemplateFormName

The power of this method is that if you need to make a change to all the menus, you only need to change the template form then rebuild and all the inherited forms will be changes as well.

Let us know if you have more questions.
 
Last edited:
Top Bottom