Home All Groups Group Topic Archive Search About

Cannot Get MenuItem's name[Notsolved]

Author
29 Mar 2005 3:22 AM
Agnes
I understand that Name is not the property of Menuitem.
I try the following web site provide by Mick
There's a MenuExtender example on my site that adds a Tag  and RadioGroup
property to menuitems.
You will find source in both VB and C#
http://dotnetrix.co.uk/menus.html

I know how to  fill the property now, HOWEVER, During Form load, How can I
get that menuitem's Tag property??
I try .Me.newmenuItem.XXX <-- There is no such property in coding ??
Please help

Author
29 Mar 2005 8:29 AM
Cor Ligthert
Agnes,

There is no menuitem.tag
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsmenuitemmemberstopic.asp

Therefore the only thing I can come up to is to create your own menuitem
class. I made a little sample for you.

\\\Needs only a blanco application and pasting this in.
Friend WithEvents MainMenu1 As MainMenu
Friend WithEvents MenuItem1 As MenuItemAgnes
    Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
        MainMenu1 = New MainMenu
        MenuItem1 = New MenuItemAgnes
        MainMenu1.MenuItems.Add(MenuItem1)
        MenuItem1.Text = "Agnes"
        MenuItem1.Tag = "Whatever"
        Me.Menu = Me.MainMenu1
End Sub
Private Sub MenuItem1_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles MenuItem1.Click
        MessageBox.Show(MenuItem1.Tag.ToString)
End Sub
End Class
Friend Class MenuItemAgnes
    Inherits MenuItem
    Private mTag As Object
    Public Property Tag() As Object
        Get
            Return mTag
        End Get
        Set(ByVal Value As Object)
            mTag = Value
        End Set
    End Property
End Class
///

I hope this helps a little bit?

Cor
Author
29 Mar 2005 9:36 AM
Mick Doherty
Hi Cor,
Agnes was refering to the extended Tag property from my MenuExtender
example.

I answered this in other thread.

Show quoteHide quote
"Cor Ligthert" <notmyfirstn***@planet.nl> wrote in message
news:%23dNBEmDNFHA.2736@TK2MSFTNGP09.phx.gbl...
> Agnes,
>
> There is no menuitem.tag
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsmenuitemmemberstopic.asp
>
> Therefore the only thing I can come up to is to create your own menuitem
> class. I made a little sample for you.
>
> \\\Needs only a blanco application and pasting this in.
> Friend WithEvents MainMenu1 As MainMenu
> Friend WithEvents MenuItem1 As MenuItemAgnes
>    Private Sub Form1_Load(ByVal sender As System.Object, _
>    ByVal e As System.EventArgs) Handles MyBase.Load
>        MainMenu1 = New MainMenu
>        MenuItem1 = New MenuItemAgnes
>        MainMenu1.MenuItems.Add(MenuItem1)
>        MenuItem1.Text = "Agnes"
>        MenuItem1.Tag = "Whatever"
>        Me.Menu = Me.MainMenu1
> End Sub
> Private Sub MenuItem1_Click(ByVal sender As Object, _
>    ByVal e As System.EventArgs) Handles MenuItem1.Click
>        MessageBox.Show(MenuItem1.Tag.ToString)
> End Sub
> End Class
> Friend Class MenuItemAgnes
>    Inherits MenuItem
>    Private mTag As Object
>    Public Property Tag() As Object
>        Get
>            Return mTag
>        End Get
>        Set(ByVal Value As Object)
>            mTag = Value
>        End Set
>    End Property
> End Class
> ///
>
> I hope this helps a little bit?
>
> Cor
>
Author
29 Mar 2005 10:08 AM
Cor Ligthert
Mick,

I was reading topdown, I saw later that there was already a long thread with
you involved, however than I had already made that sample and when you have
sent something you cannot correct that anymore.

I would have made another message when I had understood that in advance.

(You probably know the text from that already)

:-)

Cor
Author
15 Apr 2005 2:07 PM
Scott Wheeler via DotNetMonster.com
Hi Mick,

I just ran across your solution for adding a 'Tag' member to MenuItem. I'm
afraid I am experiencing the same problem as Agnes in that I don't see the
new member when I instantiate the new object. You indicated that you
answered this problem in another thread but I have no idea where that
thread is. Could you possibly share that solution again.

This functionality could be a godsend for me as part of my application
development. I appreciate your offering it for no cost to the community.

Most sincerely,

Scott Wheeler
ScottWhee***@fuse.net
Author
15 Apr 2005 3:50 PM
Mick Doherty
Access it in exactly the same way you would access TooltipText provided by a
Tooltip Component.

For Each mi As MenuItem In Me.Menu.MenuItems
    If Not MenuExtender1.GetTag(mi) Is Nothing Then
        MessageBox.Show(MenuExtender1.GetTag(mi).ToString)
    End If
Next

....of course this only checks toplevel menuitems so you'll need a recursive
method to check all the others.

Show quoteHide quote
"Scott Wheeler via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in
message news:e6dbc8cb1b1d462a89e1226a4fc8a757@DotNetMonster.com...
> Hi Mick,
>
> I just ran across your solution for adding a 'Tag' member to MenuItem. I'm
> afraid I am experiencing the same problem as Agnes in that I don't see the
> new member when I instantiate the new object. You indicated that you
> answered this problem in another thread but I have no idea where that
> thread is. Could you possibly share that solution again.
>
> This functionality could be a godsend for me as part of my application
> development. I appreciate your offering it for no cost to the community.
>
> Most sincerely,
>
> Scott Wheeler
> ScottWhee***@fuse.net