216
Chương 6: Windows Form
// Chép các item từ menu File vào menu ngữ cảnh.
foreach (MenuItem mnuItem in mnuFile.MenuItems) {
mnuContext.MenuItems.Add(mnuItem.CloneMenu());
}
// Gắn menu ngữ cảnh vào TextBox.
TextBox1.ContextMenu = mnuContext;
}
private void TextBox1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e) {
if (e.Button == MouseButtons.Right){
TextBox1.ContextMenu.Show(TextBox1, new Point(e.X, e.Y));
}
}
private void mnuOpen_Click(object sender, System.EventArgs e) {
MessageBox.Show("This is the event handler for Open.");
}
private void mnuSave_Click(object sender, System.EventArgs e) {
MessageBox.Show("This is the event handler for Save.");
}
private void mnuClick_Click(object sender, System.EventArgs e) {
MessageBox.Show("This is the event handler for Exit.");
}
}