Thank you, Marc, and thank you, Carl and Goran.
Marc, you supplied the final missing piece for me.
For the benefit of others, here's what I did:
1. I added a "contextMenuStrip" control to my form (leaving the
default Name of "contextMenuStrip1").
2. For the control that the User is going to right-click on, I set the
value of its "ContextMenuStrip" property to "contextMenuStrip1".
3. I double-clickedon the "Opening" Event in the Properties window of
contextMenuStrip1.
Within that "private void contextMenuStrip1_Opening(object sender,
CancelEventArgs e)" method, I did the following:
contextMenuStrip1.Items.Clear();
contextMenuStrip1.Items.Add("myitem1");
contextMenuStrip1.Items[contextMenuStrip1.Items.Count - 1].Enabled =
true;
contextMenuStrip1.Items[contextMenuStrip1.Items.Count - 1].Click +=
new EventHandler(mDoRightClickAction);
contextMenuStrip1.Items.Add("myitem2");
contextMenuStrip1.Items[contextMenuStrip1.Items.Count - 1].Enabled =
true;
contextMenuStrip1.Items[contextMenuStrip1.Items.Count - 1].Click +=
new EventHandler(mDoRightClickAction);
4. I created a method called mDoRightClickAction, as follows:
private void mDoRightClickAction(object sender, System.EventArgs e)
{
MessageBox.Show(sender.ToString());
}
That MessageBox.Show will display either "myitem1" or "myitem2",
depending on whichitemthe User clicks on.
Thanks again, everyone,
Rex
=====================================================
=====================================================
=====================================================
Hi All - In the following method (the click event of my Context Menu
control):
private void contextMenuStrip1_MouseClick(object sender,
MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
MessageBox.Show("left click");
}
}
the message "left click" successfully appears. What I can't figure out
(and this might be obvious!) is how to determine WHICH of the 5 menu
items that are found on my Context Menu that the Userclicked.
Thanks,
Rex- Ocultar texto citado -
- Mostrar texto citado -