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.

  1. Create menus: File, Edit, Format, Help.
  2. Add items: New, Open, Save, Save As, Exit.
  3. Add Edit menu: Cut, Copy, Paste, Select All.
  4. Add Format menu: Word Wrap, Font.
  5. Add Help menu: About.
  6. 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.