Form.ContextMenu
using System;
using System.Drawing;
using System.Windows.Forms;
class ContextMenuDemo: Form
{
MenuItem miColor;
public static void Main()
{
Application.Run(new ContextMenuDemo());
}
public ContextMenuDemo()
{
EventHandler eh = new EventHandler(MenuColorOnClick);
MenuItem[] ami = { new MenuItem("Black", eh),
new MenuItem("Blue", eh),
new MenuItem("Green", eh),
new MenuItem("White", eh) };
foreach (MenuItem mi in ami)
mi.RadioCheck = true;
miColor = ami[3];
miColor.Checked = true;
BackColor = Color.FromName(miColor.Text);
ContextMenu = new ContextMenu(ami);
}
void MenuColorOnClick(object obj, EventArgs ea)
{
miColor.Checked = false;
miColor = (MenuItem) obj;
miColor.Checked = true;
BackColor = Color.FromName(miColor.Text);
}
}
Related examples in the same category