programatically creating Menus

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi all,

I tried creating menus programatically using the MENUITEM and the MAINMENU object. Everything is fine but how come the menuitem object does not have any property to which i could add some information which would make it unique in all the menus on that form like either a 'name' or 'tag' or any other such property.

Right now the only property is index which makes the menu unique in only the menuitems of it's parent. My program requires me to know which menu the user has clicked on and there might be a possiblity that 2 menus would have the same caption.

Please let me know if there is any possible way i could tag some information to each of the menus.

thanks
Juno
 
Hi Juno,

Given that you are not doing these menus with the Designer, I would
recommend that you derive your own class using MenuItem as the base. Then you
can add your identifying data.

In use, the menu will be just the same to the User, but in Menu_Click,
etc, 'sender' will be a MenuItemJunoStyle which will have the info that you
require.

Regards,
Fergus
 
Hi Juno,

Given that you are not doing these menus with the Designer, I would
recommend that you derive your own class using MenuItem as the base. Then you
can add your identifying data.

In use, the menu will be just the same to the User, but in Menu_Click,
etc, 'sender' will be a MenuItemJunoStyle which will have the info that you
require.

Regards,
Fergus

As Fergus said:

Public Class TaggedMenuItem
Inherits MenuItem

Protected mTag As Object

Public Sub New()
MyBase.New()
End Sub

Public Sub New(ByVal text As String)
MyBase.New(text)
End Sub

' Implement the rest of the constructors if you want

Public Property Tag() As Object
Get
Return mTag
End Get
Set(ByVal Value As Object)
mTag = Value
End Set
End Property

End Class
 
Hi Andy,

Way to go!! ;-)

Regards,
Fergus

I'd just finished typing it when your post arrived, so I thought
"bugger it", and posted the code anyway!

I had to spend a couple of minutes checking that,
a) I had my line wrapping set correctly, and
b) I had my reply marker set correctly. ;)


Rgds,
 
Hi Andy,

Lol, I don't know why you'd say 'bugger it'. I gave words, you gave code -
that's a complete solution! ;-)

Regards,
Fergus
 
Back
Top