|
-
Apr 1st, 2004, 09:56 AM
#1
Thread Starter
Junior Member
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.
-
Apr 1st, 2004, 10:15 AM
#2
Frenzied Member
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
-
Apr 1st, 2004, 10:30 AM
#3
Thread Starter
Junior Member
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...
-
Apr 1st, 2004, 12:25 PM
#4
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|