468,496 Members | 1,798 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,496 developers. It's quick & easy.

Creating MenuItems programaticialy

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.


Nov 20 '05 #1
0 665

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Yigit Ozgul | last post: by
reply views Thread by Deutsche Dogge | last post: by
reply views Thread by Kreisquadratur | last post: by
1 post views Thread by Steve Tan | last post: by
5 posts views Thread by Davie | last post: by
4 posts views Thread by Ray Cassick \(Home\) | last post: by
2 posts views Thread by csgraham74 | last post: by
3 posts views Thread by active | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.