MenuItem question
-
Public Class BaseForm
Inherits System.Windows.Forms.Form
......
Friend WithEvents MnuBaseFile As System.Windows.Forms.MenuItem
Friend WithEvents MnuBaseWindow As System.Windows.Forms.MenuItem
Friend WithEvents MnuBaseFileExit As System.Windows.Forms.MenuItem
....
For Each fp In My.Forms.GetType.GetProperties
If fp.Name = "BaseForm" Then
For Each mnu As MenuItem In Me.Menu.MenuItemsHere I can get mnu.text = &File, But mnu.Name = "", Nothing. And I try to use the following block:
Dim fi As System.Reflection.FieldInfo() = bfType.GetFields(BindingFlags.NonPublic Or BindingFlags.Instance Or BindingFlags.DeclaredOnly)
For Each f As System.Reflection.FieldInfo In fi
If (f.FieldType.Name.ToString() = "MenuItem") Then
mnuNameStr = f.Name.Remove(0, 1)
End IfNow I can get field's name, but I can't use field to set text for the menu. How can I get a field's name, the Menuitem's name, then set the text for the Menuitem?
-
Public Class BaseForm
Inherits System.Windows.Forms.Form
......
Friend WithEvents MnuBaseFile As System.Windows.Forms.MenuItem
Friend WithEvents MnuBaseWindow As System.Windows.Forms.MenuItem
Friend WithEvents MnuBaseFileExit As System.Windows.Forms.MenuItem
....
For Each fp In My.Forms.GetType.GetProperties
If fp.Name = "BaseForm" Then
For Each mnu As MenuItem In Me.Menu.MenuItemsHere I can get mnu.text = &File, But mnu.Name = "", Nothing. And I try to use the following block:
Dim fi As System.Reflection.FieldInfo() = bfType.GetFields(BindingFlags.NonPublic Or BindingFlags.Instance Or BindingFlags.DeclaredOnly)
For Each f As System.Reflection.FieldInfo In fi
If (f.FieldType.Name.ToString() = "MenuItem") Then
mnuNameStr = f.Name.Remove(0, 1)
End IfNow I can get field's name, but I can't use field to set text for the menu. How can I get a field's name, the Menuitem's name, then set the text for the Menuitem?
-
Public Class BaseForm
Inherits System.Windows.Forms.Form
......
Friend WithEvents MnuBaseFile As System.Windows.Forms.MenuItem
Friend WithEvents MnuBaseWindow As System.Windows.Forms.MenuItem
Friend WithEvents MnuBaseFileExit As System.Windows.Forms.MenuItem
....
For Each fp In My.Forms.GetType.GetProperties
If fp.Name = "BaseForm" Then
For Each mnu As MenuItem In Me.Menu.MenuItemsHere I can get mnu.text = &File, But mnu.Name = "", Nothing. And I try to use the following block:
Dim fi As System.Reflection.FieldInfo() = bfType.GetFields(BindingFlags.NonPublic Or BindingFlags.Instance Or BindingFlags.DeclaredOnly)
For Each f As System.Reflection.FieldInfo In fi
If (f.FieldType.Name.ToString() = "MenuItem") Then
mnuNameStr = f.Name.Remove(0, 1)
End IfNow I can get field's name, but I can't use field to set text for the menu. How can I get a field's name, the Menuitem's name, then set the text for the Menuitem?
Sorry ... I don't understand what you trying to achieve ... Could you explain it once more (perhaps with an example) ?
-
Sorry ... I don't understand what you trying to achieve ... Could you explain it once more (perhaps with an example) ?
I want to change the Text of a Menuitem dynamically in runtime. I can get a Menuitem in the Menuitems collection, but it's Name property is empty.
For Each fp In My.Forms.GetType.GetProperties
If fp.Name = "BaseForm" Then
For Each mnu As MenuItem In Me.Menu.MenuItemsBut in property window, the Menuitem has Name property, it's same as a name of field variable, like: MnuBaseFile
-
I want to change the Text of a Menuitem dynamically in runtime. I can get a Menuitem in the Menuitems collection, but it's Name property is empty.
For Each fp In My.Forms.GetType.GetProperties
If fp.Name = "BaseForm" Then
For Each mnu As MenuItem In Me.Menu.MenuItemsBut in property window, the Menuitem has Name property, it's same as a name of field variable, like: MnuBaseFile
The Problem is that you ask the wrong question to the wrong partner. As I understand : MenuItem is a Control on your Form - which type has it ? Why do you search inside the Forms.Properties ? You should search it inside the Form.Controls-Collection. I could specify it with more information from you.