joe_pool_is
Contributor
I've got one Context Menu named mi_EasterEggs with three (3) menu items:
* mi_FontArial
* mi_FontCourier
* mi_RawData
All menu items have their Visible properties set to False.
This context menu is included in 1 ListView control and 1 TextBox control.
When one of these controls is right-clicked (to bring up the Context Menu), I want to make menu items viisble depending on what item was right-clicked.
I tried this code, but the sender is always the mi_EasterEggs Menu Item:
I searched some posts here on Context Menus and saw where Plausibly said to look at the .SourceControl field, so I modified my listing to this:
It still doesn't work, though.
What am I doing wrong?
Also, I'd like to still have the default Context Menu for the TextBox Control, but this is a bonus and is not necessary. First thing is first, right?
* mi_FontArial
* mi_FontCourier
* mi_RawData
All menu items have their Visible properties set to False.
This context menu is included in 1 ListView control and 1 TextBox control.
When one of these controls is right-clicked (to bring up the Context Menu), I want to make menu items viisble depending on what item was right-clicked.
I tried this code, but the sender is always the mi_EasterEggs Menu Item:
Code:
private void mi_EasterEggs_Opening(object sender, CancelEventArgs e) {
if (sender.Equals(ListView1) == true) {
mi_RawView.Visible = (0 < ListView1.Items.Count);
} else {
mi_FontArial.Visible = sender.Equals(TextBox1);
mi_FontCourier.Visible = sender.Equals(TextBox1);
mi_RawView.Visible = false;
}
}
Code:
private void mi_EasterEggs_Opening(object sender, CancelEventArgs e) {
if (mi_EasterEggs.SourceControl == ListView1) {
mi_RawView.Visible = (0 < ListView1.Items.Count);
} else {
mi_FontArial.Visible = (mi_EasterEggs.SourceControl == TextBox1);
mi_FontCourier.Visible = (mi_EasterEggs.SourceControl == TextBox1);
mi_RawView.Visible = false;
}
}
What am I doing wrong?
Also, I'd like to still have the default Context Menu for the TextBox Control, but this is a bonus and is not necessary. First thing is first, right?