Results 1 to 4 of 4

Thread: Getting Menu Name **SOLVED**

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2003
    Posts
    24

    Getting Menu Name **SOLVED**

    Hi all, simple question today... or so I thought

    How do I retrieve the name of a menu ?

    I've used the designer to build menus for my application and in the designer, you can set names to your menus like : mnuFile, mnuExit etc...

    In my code, I loop through my controls list and come across a menuitem object and would want to have his name... but it looks like the .Name property isn't available for MenuItems.... Strange and plain stupid if you ask me...


    I get the Handle on the menu so I figured there could be a Rock Around for this.... searched the web, google, many msgbrd, couldn't find anything....


    As anyone ever try to do this and actually succeeded ???

    Thx for your help and time.

    PS: Don't be afraid to point me to your Questions in this forum as I'd be glad to help you out
    Last edited by 1337_Vince; Apr 1st, 2004 at 12:25 PM.

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    Menu items don't have names of any kind. They're just objects like everything else.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2003
    Posts
    24
    They're just objects like everything else.
    hmmmm ???

    Why is it then that when I loop through my controls collection and come across a LABEL, I can get his Name but it wont work for ItemMenus ???

    EX:

    Dim ctl as control

    For Each ctl In me.Controls

    If TypeOf ctl Is Label Then

    ctl.Text = resManager.GetString(ctl.Name.ToString)
    End If

    next



    This works, but dont try to do a case for MenuItems because it will simply tell you that the Name property isnt valid for ItemMenus...

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2003
    Posts
    24
    Got it....


    Public Sub PrintMenuNames()

    Dim fields() As System.Reflection.FieldInfo = Me.GetType().GetFields(System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Public Or System.Reflection.BindingFlags.Static Or System.Reflection.BindingFlags.Instance)
    Dim field As System.Reflection.FieldInfo

    For Each field In fields
    If CType(field.FieldType, System.Type) Is GetType(System.Windows.Forms.MenuItem) Then
    Debug.WriteLine(field.Name)
    End If
    Next

    End Sub



    Viva la Reflection !!!
    Last edited by 1337_Vince; Apr 1st, 2004 at 12:29 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width