I am in a bit of a bind. I can't believe I cannot figure this out but I have
been at it all day and it is just not coming to me.
I am building menus on a form based upon an XML file. I have created a class
to do this and that part is all working just fine. My problem is the event
handler where I want all the click events to go. Not really building the
event hander, just determining the individual menuItem that triggered the
handler is my problem.
My event handler looks like this:
Private Sub MenuClick(ByVal sender As Object, ByVal e As System.EventArgs)
Dim menuItem As MenuItem
menuItem = sender
Debug.WriteLine("--" & menuItem.Text)
End Sub
What I want to be able to do it look at something on the sender object (like
a name or tag property) and determine what exact MenuItem triggered the
event (I have all my menuitems going to the same handler).
I thought that when I was creating my individual MenuItems I would be able
to assign each of them an individual name like:
mnuFile
mnuFileNew
mnuFileNewMessage
.... etc ...
and then be able to get then in code as something like sender.name or
something, but I can't seem to be able to do that.
All that I seem to be able to do it get the Text of the sender and this just
gets me the menu text, not really helpful in the long run.
Besides rolling my own MenuItem class just to add some type of property like
Tag or Name, is there any way that I can do this? I know that I can use
sender.GetType().Name but all this does is return the string 'MenuItem' and
that is no good to me. 4 1214
Hi,
The hashtable allows you store items based on a key. The key is of
the object type. Why dont you store what you want to be a tag in a
hashtable with the menuitem as the key.
Ken
--------------
"Ray Cassick (Home)" <rc************@enterprocity.com> wrote in message
news:OA**************@TK2MSFTNGP09.phx.gbl... I am in a bit of a bind. I can't believe I cannot figure this out but I
have been at it all day and it is just not coming to me.
I am building menus on a form based upon an XML file. I have created a
class to do this and that part is all working just fine. My problem is the event handler where I want all the click events to go. Not really building the event hander, just determining the individual menuItem that triggered the handler is my problem.
My event handler looks like this:
Private Sub MenuClick(ByVal sender As Object, ByVal e As System.EventArgs)
Dim menuItem As MenuItem
menuItem = sender
Debug.WriteLine("--" & menuItem.Text)
End Sub
What I want to be able to do it look at something on the sender object
(like a name or tag property) and determine what exact MenuItem triggered the event (I have all my menuitems going to the same handler).
I thought that when I was creating my individual MenuItems I would be able to assign each of them an individual name like:
mnuFile mnuFileNew mnuFileNewMessage ... etc ...
and then be able to get then in code as something like sender.name or something, but I can't seem to be able to do that.
All that I seem to be able to do it get the Text of the sender and this
just gets me the menu text, not really helpful in the long run.
Besides rolling my own MenuItem class just to add some type of property
like Tag or Name, is there any way that I can do this? I know that I can use sender.GetType().Name but all this does is return the string 'MenuItem'
and that is no good to me.
Hi,
The hashtable allows you store items based on a key. The key is of
the object type. Why dont you store what you want to be a tag in a
hashtable with the menuitem as the key.
Ken
--------------
"Ray Cassick (Home)" <rc************@enterprocity.com> wrote in message
news:OA**************@TK2MSFTNGP09.phx.gbl... I am in a bit of a bind. I can't believe I cannot figure this out but I
have been at it all day and it is just not coming to me.
I am building menus on a form based upon an XML file. I have created a
class to do this and that part is all working just fine. My problem is the event handler where I want all the click events to go. Not really building the event hander, just determining the individual menuItem that triggered the handler is my problem.
My event handler looks like this:
Private Sub MenuClick(ByVal sender As Object, ByVal e As System.EventArgs)
Dim menuItem As MenuItem
menuItem = sender
Debug.WriteLine("--" & menuItem.Text)
End Sub
What I want to be able to do it look at something on the sender object
(like a name or tag property) and determine what exact MenuItem triggered the event (I have all my menuitems going to the same handler).
I thought that when I was creating my individual MenuItems I would be able to assign each of them an individual name like:
mnuFile mnuFileNew mnuFileNewMessage ... etc ...
and then be able to get then in code as something like sender.name or something, but I can't seem to be able to do that.
All that I seem to be able to do it get the Text of the sender and this
just gets me the menu text, not really helpful in the long run.
Besides rolling my own MenuItem class just to add some type of property
like Tag or Name, is there any way that I can do this? I know that I can use sender.GetType().Name but all this does is return the string 'MenuItem'
and that is no good to me.
Interesting... Using the actual object as the key...
I will have to give it a try.. Thanks for the suggestion.
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:#A**************@TK2MSFTNGP09.phx.gbl... Hi,
The hashtable allows you store items based on a key. The key is
of the object type. Why dont you store what you want to be a tag in a hashtable with the menuitem as the key.
Ken -------------- "Ray Cassick (Home)" <rc************@enterprocity.com> wrote in message news:OA**************@TK2MSFTNGP09.phx.gbl... I am in a bit of a bind. I can't believe I cannot figure this out but I have been at it all day and it is just not coming to me.
I am building menus on a form based upon an XML file. I have created a class to do this and that part is all working just fine. My problem is the
event handler where I want all the click events to go. Not really building the event hander, just determining the individual menuItem that triggered
the handler is my problem.
My event handler looks like this:
Private Sub MenuClick(ByVal sender As Object, ByVal e As
System.EventArgs) Dim menuItem As MenuItem
menuItem = sender
Debug.WriteLine("--" & menuItem.Text)
End Sub
What I want to be able to do it look at something on the sender object (like a name or tag property) and determine what exact MenuItem triggered the event (I have all my menuitems going to the same handler).
I thought that when I was creating my individual MenuItems I would be
able to assign each of them an individual name like:
mnuFile mnuFileNew mnuFileNewMessage ... etc ...
and then be able to get then in code as something like sender.name or something, but I can't seem to be able to do that.
All that I seem to be able to do it get the Text of the sender and this just gets me the menu text, not really helpful in the long run.
Besides rolling my own MenuItem class just to add some type of property like Tag or Name, is there any way that I can do this? I know that I can use sender.GetType().Name but all this does is return the string 'MenuItem' and that is no good to me.
Interesting... Using the actual object as the key...
I will have to give it a try.. Thanks for the suggestion.
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:#A**************@TK2MSFTNGP09.phx.gbl... Hi,
The hashtable allows you store items based on a key. The key is
of the object type. Why dont you store what you want to be a tag in a hashtable with the menuitem as the key.
Ken -------------- "Ray Cassick (Home)" <rc************@enterprocity.com> wrote in message news:OA**************@TK2MSFTNGP09.phx.gbl... I am in a bit of a bind. I can't believe I cannot figure this out but I have been at it all day and it is just not coming to me.
I am building menus on a form based upon an XML file. I have created a class to do this and that part is all working just fine. My problem is the
event handler where I want all the click events to go. Not really building the event hander, just determining the individual menuItem that triggered
the handler is my problem.
My event handler looks like this:
Private Sub MenuClick(ByVal sender As Object, ByVal e As
System.EventArgs) Dim menuItem As MenuItem
menuItem = sender
Debug.WriteLine("--" & menuItem.Text)
End Sub
What I want to be able to do it look at something on the sender object (like a name or tag property) and determine what exact MenuItem triggered the event (I have all my menuitems going to the same handler).
I thought that when I was creating my individual MenuItems I would be
able to assign each of them an individual name like:
mnuFile mnuFileNew mnuFileNewMessage ... etc ...
and then be able to get then in code as something like sender.name or something, but I can't seem to be able to do that.
All that I seem to be able to do it get the Text of the sender and this just gets me the menu text, not really helpful in the long run.
Besides rolling my own MenuItem class just to add some type of property like Tag or Name, is there any way that I can do this? I know that I can use sender.GetType().Name but all this does is return the string 'MenuItem' and that is no good to me.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Venkatesh |
last post by:
Hi Everybody,
This is the first timw I am entering into this Group.
I am developing a VB Project with an MDI form.
I want to display IE Favorites into my application. For this I need to...
|
by: Deutsche Dogge |
last post by:
Hi. I'M having a weird problem with addign menuitems to a menu dynamically
on the popup event of the menuitem containing the container of the
menuitems i wanna add (tools -> external -> {list of...
|
by: Kreisquadratur |
last post by:
Below is s snippet of my code, which should add menuitems as a submenu
of an item in a contextmenu. But only the first time the contextmenu
opens the entrys are set correctly. I just don't know why...
|
by: Steve Tan |
last post by:
1. How can I loop through all the items and subitems for Menu of a
Windows Form (c#) ? Recursive function?
2. How can I uniquely identify a submenu item ? MenuItems doesn't have
a Name...
|
by: Brian |
last post by:
Create a simple MDI form and a child form, and try the following simple code
to add a new menu item on the Edit menu popup:
private void editMenu_Popup(object sender, System.EventArgs e)
{...
|
by: Davie |
last post by:
I'm developing an application on the smartphone. To reduce the size of the application i'm using panels where appropriate instead of forms. As a result of the design, I need to have different...
|
by: Ray Cassick \(Home\) |
last post by:
I am in a bit of a bind. I can't believe I cannot figure this out but I have
been at it all day and it is just not coming to me.
I am building menus on a form based upon an XML file. I have...
|
by: csgraham74 |
last post by:
Hi there,
just wondering if someone could help me. Ive written some code in
vb.net to create the following xml.
<menu>
<menuItem>
<text>Political Update</text>
</menuItem>
<subMenu />
|
by: active |
last post by:
I have a mainmenu menuitem
that contains a Recently Used Files menuitem
If at design time I include a menuitem in the Recently Used Files menuitem
collection it will display OK
If I...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |