473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

WinForm Dynamic Context Menu

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?
Oct 8 '08 #1
1 5561
From memory, I think the contect menu wont open unless it has something to
display, change the logic so at form load the items are visible, then hide
the non-required ones when opening the menu rather than the other way round.
--
Ciaran O''Donnell
http://wannabedeveloper.spaces.live.com
"jp2msft" wrote:
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?
Oct 9 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Eddie de Bear | last post by:
Hi, A project I am working on has a requirement for dynamic menus. For the most part this works really well. The menus I'm creating a based on files and directories, so naturally the menu...
6
by: Ed Sutton | last post by:
I am dynamically appending to a context menu when user right mouse clicks on a treeView. The first time I right-mouse click I see the appended menu. Subsequently, the menu items I append do not...
8
by: Dennis C. Drumm | last post by:
Is there a way to modify the standard context menu shown when someone right clicks in a windows text box and that would work for all open windows applications? The standard context menu for...
6
by: QuenHo | last post by:
Hi All, I've build a winform application with vb.net which accepts command-line parameters. If I tell windows to open certain files with this application all works fine, but windows does NOT...
1
by: Chris Murphy via DotNetMonster.com | last post by:
Hi all, I'm just wondering if any one can help me with this development issue I'm having. I've created a customized treeview control to handle the particular tasks to which I'll be using it. Within...
3
by: RahimAsif | last post by:
I am writing an application that requires the a portion of the main menu to be dynamic. The menu has file, panels, view files and help across the top. The view files sub menu needs to be...
2
by: Ron M. Newman | last post by:
Hi, Just need a little advice. Id like to build *dynamic* context menus for tree nodes. I'm pretty versed in building context menus and attaching them to tree nodes. My question is, what...
1
by: cdmsenthil | last post by:
I have an Infragistics UltrawebGrid . Each Row in the grid is attached to a context menu using Infragistics CSOM Upon click on the menu, I am creating an Iframe dynamically which points to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.