473,503 Members | 1,629 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 2998
"eaguilar" <ea******@discussions.microsoft.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******@discussions.microsoft.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
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>
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
1469
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...
1
1355
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...
2
1614
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...
2
9767
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. ...
2
3425
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...
8
2089
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...
2
5891
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...
1
3396
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...
4
1835
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...
0
7278
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
7458
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...
0
5578
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,...
1
5013
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...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
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...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.