using System; using System.Drawing; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Shown(object sender, EventArgs e) { contextMenuStrip1.KeyDown += new KeyEventHandler(contextMenuStrip1_KeyDown); contextMenuStrip1.Closed += new ToolStripDropDownClosedEventHandler(contextMenuStrip1_Closed); ContextMenuStrip cms = new ContextMenuStrip(); ToolStripItem item1 = new ToolStripMenuItem(); item1.Text = "テスト1"; cms.Items.Add(item1); contextMenuStrip1 = cms; contextMenuStrip1.Show(new Point(0, 0)); } void contextMenuStrip1_Closed(object sender, ToolStripDropDownClosedEventArgs e) { MessageBox.Show("メニューが閉じられました"); } void contextMenuStrip1_KeyDown(object sender, KeyEventArgs e) { MessageBox.Show("キーが押されました"); } } }