R
Ray Cassick \(Home\)
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.
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.