471,071 Members | 966 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

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:

.... 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 687

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

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.