Free computer Tutorials

home
Stay at Home and Learn

Adding Menus to a Visual Basic .NET Form

 
Computer Tutorials List

 

 

 

 

 

In this section we’ll see how to add menus to a Visual Basic .NET form. These type of menus are very common to Windows programme. Visual Basic itself has many of these drop down menus - File, Edit, View, Project, Format, etc. And they’re very easy to add.

 

Start a new project. To your new form, use the toolbox to add a Main Menu control:

The MainMenu Item on the Toolbox

Double click the control to add one to your form. When you do, you'll notice two things. At the top of your form, you'll see this:

A menu has been added to the form

We'll see how to construct our menu soon. But notice the other things that gets added to your project. Examine the bottom of your screen, on the left. You'll see this:

The Menu Object

This is the control itself. If you click on this (it's highlighted above), you'll see that the Properties box on the right changes. There are many properties for the control. But there are lots of properties for the MenuItem object. The MenuItem object is the one at the top of the form - The one that says Type Here.

To start building your menu, click on the MenuItem object. It will change to this:

The cursor wil be flashing in the white text area

The "Type Here" box moves down one place. You get a second "Type Here" area to the right of the first one. This is for the second drop-down menu.

Type the word File in the textbox at the top, and the press the return key on your keyboard. You'll see this:

File is the main menu item

Click inside the blue "Type Here" area, and the menu changes to this:

An item for the File menu can now be added

Type the word New , and then hit your return key. You should then have this:

A New option added to the menu

Add an Open and a Save item to your menu in the same way. It should look like this:

Open and Save options have been added

The final item we'll add to our menu is an "Exit" item. But you can add a separator between the "Save" and "Exit".

 

No more reading these lessons online - get the eBook here!

 

To add a separator, click inside the blue "Type Here" box. Instead of typing a letter, type the minus character "-" (in between the "0" key and the "+/=" key on your keyboard). When you hit your return key, you'll see the separator appear:

A separator has been added below Save

Click inside the blue "Type Here" area, and add an Exit item. Click back on your form, away from the menu, to finish off. You should now have a File menu like this one:

The Exit option has been added

To see what your menu look like, Run your programme. Click the File menu and you should have one that looks like this:

The Menu when you run the prorgramme

We haven't added any code to the menu yet. So nothing will happen if you click an item on the menu. But it does look quite good. Very professional!

 

In the next part, we'll see how to add some code to the Exit menu.

 

Click here to learn how to add code to your VB .NET Menus -->

<--Back to the .NET Contents Page

View all our Home Study Computer Courses