C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
And: This will add the File, Edit, Tools and Help menus with standard sub-menu items.
Note: None of these entries will actually have any effect if you click on them. This will be fixed in the next step.
Here: I simply call MessageBox.Show when the New or Open items are used. This displays a nice dialog box.
MessageBoxC# program that implements Click event handlers
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("New command executed");
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("Open command executed");
}
}
}
Output
Message boxes will appear when New/Open are clicked.
Message boxes will appear when Ctrl-N/Ctrl-O are pressed.
Also: The Separator is a simple horizontal line. The TextBox allows the user to enter text inline in a menu.
Tip: To use access keys, please press Alt and then the letters directing to your command. So to use Open, press Alt-F-O.
Tip: There are icon sets available (from Microsoft and other organizations) that you can use to add free icons to your program.
Also: Visual Studio gives you the option to instantly add the default items. You can then use the Click event handler.