J
jp2msft
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 when the form loads.
This context menu is included in one (1) ListView control and one (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:
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;
}
}
I searched google and found a suggestion by Plausibly Damp where he
mentioned usingt the .SourceControl field, so I modified my listing to this:
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;
}
}
It still doesn't work, though.
What am I doing wrong?
Also, I'd like to still have the default Context Menu for the Controls, 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 when the form loads.
This context menu is included in one (1) ListView control and one (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:
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;
}
}
I searched google and found a suggestion by Plausibly Damp where he
mentioned usingt the .SourceControl field, so I modified my listing to this:
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;
}
}
It still doesn't work, though.
What am I doing wrong?
Also, I'd like to still have the default Context Menu for the Controls, but
this is a bonus and is not necessary.
First thing is first, right?