MenuStrip Control in C#.Net
Where the MenuStrip class is the foundation of menus functionality in Windows Forms.
If you have worked with menus in .NET 1.0 and 2.0, you must be familiar with the MainMenu control.
In .NET 3.5 and 4.0, the MainMenu control is
replaced with the MenuStrip control.
How to use MenuStrip Control
Drag and drop MenuStrip control from the toolbox on the window Form.
For creating a menu simply add a menu item in the shown textbox. Insert text in the MenuStrip which you want to display as the menu.
New and open is the sub Item of File.
Create event handlers for the above menu items as New, Open, Save, Exit on the MenuStrip and selecting submenu items then double click on them.
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void saveToolStripMenuItem_Click_1(object sender, EventArgs e)
{
}
private void exitToolStripMenuItem_Click_1(object sender, EventArgs e)
{
}
Change the Form to an MDI Form.
private void frmMenuStrip_Load(object sender, EventArgs e)
{
this.IsMdiContainer = true;
}
Write code on the Click event of the New submenu item.
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
Form fr = new Form();
fr.MdiParent = this;
fr.Text = "New";
}
Run The Project
New child Form will open when New menu item clicked.
Write code on the Click event of the Open submenu item.
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog fld = new OpenFileDialog();
fld.ShowDialog();
}
Open dialog will open when Open menu item clicked.
Write code on the Click event of the Save submenu item.
private void saveToolStripMenuItem_Click_1(object sender, EventArgs e)
{
saveFileDialog1.ShowDialog();
}
Save dialog will open when Save menu item clicked.
Write code on the Click event of the Exit submenu item.
private void exitToolStripMenuItem_Click_1(object sender, EventArgs e)
{
this.Close();
}
The form will close when the Exit menu item clicked.
MenuStrip properties
GripStyle: Gets or sets the visibility of the grip used to reposition the control.
GripMargin: Gets or sets the space around the ToolStrip move handle.
AutoSize: Gets or sets a value indicating whether the control is automatically resized to display its entire contents.
AllowMerge: Gets or sets a value indicating whether multiple MenuStrip can be combined.
Anonymous User
05-Mar-2019Thank You for the post.
mohan kumar
19-Oct-2011fr.show();
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
Form fr = new Form();
fr.MdiParent = this;
fr.Text = "New";
}
So,the above should be rewritten as
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
Form fr = new Form();
fr.MdiParent = this;
fr.Text = "New";
fr.show();
}
However,i welcome any new suggestions from you guys.. :) ;)