Menu Strip control is used to create a menu bar in the windows application.
Follow the below steps to create a menu bar.
Step 1
Drag and drop the menu strip control which is under the Menubar and Toolbar controls on to form. The below figure shows how it looks like.
Step 2
Click on the menu strip, then type the menu as shown in the below figure.
Step 3
Now, double click on the all the menu items, then the code will be generated as follows. All these are the Click events of menu items (which are default events).
[csharp]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void splessonsSignupToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void homeToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void splessonsLoginToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
[/csharp]
Now write the code to navigate another form, when one click on the menu item. For example, click on the Home menu it will open Home form -> click on SPlessons Login menu -> which opens Login form of the SPlessons.
Step 4
To Navigate other forms, first of all, one have to create forms. For example, click on the Home menu it will go to Home Form. That's the reason one have to create forms first.
To create/add forms follow the below steps.
1.Right Click on the WindowsFormsApplication1.
2.Go to Add->Windows Form.
3.Give the name for form.
After creating forms, write the code like below under the click events of menu items.
[csharp]private void splessonsSignupToolStripMenuItem_Click(object sender, EventArgs e)
{
Register obj = new Register();//creates an object for the Register form
obj.Show();//To show register form
this.Hide();//To hide the current form
}
private void homeToolStripMenuItem_Click(object sender, EventArgs e)
{
home obj = new home();//creates an object for the home form
obj.Show();//To show home form
this.Hide();//To hide the current form
}
private void splessonsLoginToolStripMenuItem_Click(object sender, EventArgs e)
{
login obj = new login();//creates an object for the login form
obj.Show();//To show login form
this.Hide();//To hide the current form
}
[/csharp]
Step 5
Click on the Home menu, it will open home form and hides current form as shown in the below figure.