Advanced
12 min read
Control #13
MenuStrip Control
MenuStrip creates professional menus like File, Edit, View, and Help. It's how users access application features.
What is a MenuStrip?
MenuStrip creates the classic menu bar at the top of applications. It can contain menu items with sub-menus, separators, shortcuts, and icons.
Code Example
// In designer, type directly in "Type Here" boxes
// File Menu
// - New
// - Open
// - ----------
// - Exit
// Event handlers
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("New file created!");
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
// Add shortcuts
// In designer, set ShortcutKeys property
// e.g., Ctrl+N for New
// Add images to menu items
// Set Image property in designer or code
Exercise
Task: Create a notepad-like application with MenuStrip.
- Create menus: File, Edit, Format, Help.
- Add items: New, Open, Save, Save As, Exit.
- Add Edit menu: Cut, Copy, Paste, Select All.
- Add Format menu: Word Wrap, Font.
- Add Help menu: About.
- Add keyboard shortcuts (Ctrl+N, Ctrl+O, Ctrl+S).
Key Takeaway
MenuStrip adds professional menus to your application. Use keyboard shortcuts and icons to make menus more user-friendly.