473,714 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic menu items and event handlers

Hi,

I am trying to dynamically generate a menu, based on entries on a text or
xml file. The text file contains the "tree" after which the menu will need to
be created. Something like the following:

Level 1
-- Level 2
-- Level 2
Level 1
-- Level 2
---- Level 3

I can read the file and generate each menu item definition, with the
corresponding "nesting", without a problem.

What I'm having difficulties with is deciding on how to handle the events
for each of the menu items. Generating the full menu dynamically would mean
having to create the event handlers dynamically, unless I have a fixed amount
of event handlers, which I'm not sure is the best approach. I might be wrong
here...

1. What's the best way to generate event handlers dynamically? I've read
about runtime IL generation, which makes sense but is a bit complex.

2. Using regular event handlers (hard coded), can I capture which of the
menu items is being clicked and what component is the menu being displayed
on? i.e., if the menu is being displayed after a right click on a button or a
picture box, can I: 1) know if it's the picture box or the button displaying
the menu? and 2) can I know what menu/sub menu is being clicked?

Any ideas will be greatly appreciated.

Thanks in advance,

</edwin>
Feb 20 '08 #1
3 3013
"eaguilar" <ea******@discu ssions.microsof t.comschrieb:
I am trying to dynamically generate a menu, based on entries on a text or
xml file. The text file contains the "tree" after which the menu will need
to
be created. Something like the following:

Level 1
-- Level 2
-- Level 2
Level 1
-- Level 2
---- Level 3

I can read the file and generate each menu item definition, with the
corresponding "nesting", without a problem.

What I'm having difficulties with is deciding on how to handle the events
for each of the menu items. Generating the full menu dynamically would
mean
having to create the event handlers dynamically, unless I have a fixed
amount
of event handlers, which I'm not sure is the best approach. I might be
wrong
here...

1. What's the best way to generate event handlers dynamically? I've read
about runtime IL generation, which makes sense but is a bit complex.
Take a look at the 'AddHandler' and 'RemoveHandler' statements.
2. Using regular event handlers (hard coded), can I capture which of the
menu items is being clicked
Check out the event handler's 'sender' parameter. It contains a reference
to the source of the event.
and what component is the menu being displayed
on?
Context menu objects have a 'SourceControl' property which references the
control the menu has been shown on.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Feb 20 '08 #2
On Wed, 20 Feb 2008 07:28:01 -0800, eaguilar
<ea******@discu ssions.microsof t.comwrote:
>Hi,

I am trying to dynamically generate a menu, based on entries on a text or
xml file. The text file contains the "tree" after which the menu will need to
be created. Something like the following:

Level 1
-- Level 2
-- Level 2
Level 1
-- Level 2
---- Level 3

I can read the file and generate each menu item definition, with the
correspondin g "nesting", without a problem.

What I'm having difficulties with is deciding on how to handle the events
for each of the menu items. Generating the full menu dynamically would mean
having to create the event handlers dynamically, unless I have a fixed amount
of event handlers, which I'm not sure is the best approach. I might be wrong
here...

1. What's the best way to generate event handlers dynamically? I've read
about runtime IL generation, which makes sense but is a bit complex.

2. Using regular event handlers (hard coded), can I capture which of the
menu items is being clicked and what component is the menu being displayed
on? i.e., if the menu is being displayed after a right click on a button or a
picture box, can I: 1) know if it's the picture box or the button displaying
the menu? and 2) can I know what menu/sub menu is being clicked?

Any ideas will be greatly appreciated.

Thanks in advance,

</edwin>
I would use AddHandler (in VB) to add a single handler to the
ItemClicked event on all of the menus. The event handler has two
arguments. 'sender' is the object (menu) that raised the event. 'e'
is the event information, and e.ClickedItem will be the item in the
'sender' menu that was clicked.

You can use various properties of the menu items (Tag, Name, Text) to
identify which item it is.

If the same set of menus are connected to multiple controls, then you
might need to handle the Opening event of the top menu and capture its
owning control at that time.
Feb 20 '08 #3
Hi Herfried, thanks for the reply.

I am already using AddHandler to create que events and their handlers, and
the sender property to access some info. Both are working fine.

SourceControl property is partially working - for "Level 1" entry objects I
can access and display the name of the control triggering the menu, but for
"higher" level entries, SourceControl returns Nothing for some reason...

Any ideas? I could send code samples if needed...

Thanks in advance again,
--
</edwin>
Feb 20 '08 #4

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

Similar topics

2
1478
by: erica | last post by:
hi!! i'm trying to make a dynamic sub-menu type thing, can't get it to work right... i have this one set up but as you can see, when you go to mouse over the sub-menu items, the sub-menu gets hidden when it should stay visible... http://www.tpmc.com/testgdi/about.html if anyone has any ideas i will love you forever!!!!
1
1368
by: Chris | last post by:
Hi, In .NET , when working with menus handlers : Is there an equivalent of an in MFC used event : UPDATE_COMMAND_UI ? For those not familiar with the name UPDATE_COMMAND_UI : it is an event that is fired when one clicks on a topmenu-item (not a childmenu-item) (example of a topmenu-item : 'Edit ' and childmenu-item would then be 'Paste' or 'Copy')
2
1630
by: mike | last post by:
i'm building an desktop windows app in C#. the main menu for the application will be different depending on the admin rights of the user. i've built the entire app. in delphi and i simply activated or deactivated the menu items in that case, but all the menu items are visble. i'm hoping / thinking that with .NET, i can dynamically generate the click events for the dynamically generated menu, so that only the menu items, that a particular...
2
9783
by: Ludwig | last post by:
My application has a main tool strip menu (File, Options, help,...). There are also a number of context menu's that popup. Some main menu items should also be available in some context menu's. Is there a way of defining these shared menu items once, and merge them in the main menu and context menu. I don't want to create the same menu's and handling the same event handlers. What approach is there for sharing menu items, so that there...
2
3450
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 event to I "capture" in order to build the tree node menu in real time? right click on a tree node? or is it too late? just FYI: the menu is different for each node and is based on "real time"
8
2108
by: gs | last post by:
I was able to set tooltips on objects other than main menu. I would like to get the effect of tooltip or microhelp in the bottom status bar when the mouse is hovering over a submenu item. How do I do that? For example in outlook express, when one expand a main menu item and holds mouse over one of the enable sub menu item, one would see some sort microhelp text in the status bar in the bottom
2
5906
by: MCM | last post by:
I'm working on a plotting control. The plotting control will have a context menu with basic commands for "scaling", "zooming", etc. Is there a way that, from the parent form, I can add more commands to the control's context menu? I'm envisioning a case where the control has a set of context menu items, and the parent form also has a set of context menu items. Thanks.
1
3424
by: Karl Rhodes | last post by:
I'm building a windows forms app in VB.net 2005 and would like to know if there is any way of adding a handler using a dynamic AddressOf value? The application will have a "Windows" menu item and I want to add a list open forms as other menu items to this list. I want to be able to do this dynamically and create a handler for each one that I add. However, instead of creating the handler everytime i open a new form, I want to use a...
4
1846
by: libish | last post by:
hi all... can any one help me by suggesting a way to get items in dynamic form? here what i'm doing is , i'm displaying a dynamic form. in that form i have a main menu and this main menu contains a menu item "OK". here the dynamic form consist of some labels, list items and all. when i click on the "OK" menu item, an event occurs and i've wrote methods which wll execute on this event. now i need the selected list item index,value.. label...
0
8801
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9314
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9174
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9015
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7953
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4464
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3158
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2520
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.