Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. MenuItem question

MenuItem question

Scheduled Pinned Locked Moved Visual Basic
question
5 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    econy
    wrote on last edited by
    #1

    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.MenuItems

    Here 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 If

    Now 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?

    E R 2 Replies Last reply
    0
    • E econy

      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.MenuItems

      Here 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 If

      Now 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?

      E Offline
      E Offline
      econy
      wrote on last edited by
      #2

      Solved, use Setvalue

      1 Reply Last reply
      0
      • E econy

        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.MenuItems

        Here 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 If

        Now 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?

        R Offline
        R Offline
        Ralf Meier
        wrote on last edited by
        #3

        Sorry ... I don't understand what you trying to achieve ... Could you explain it once more (perhaps with an example) ?

        E 1 Reply Last reply
        0
        • R Ralf Meier

          Sorry ... I don't understand what you trying to achieve ... Could you explain it once more (perhaps with an example) ?

          E Offline
          E Offline
          econy
          wrote on last edited by
          #4

          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.MenuItems

          But in property window, the Menuitem has Name property, it's same as a name of field variable, like: MnuBaseFile

          R 1 Reply Last reply
          0
          • E econy

            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.MenuItems

            But in property window, the Menuitem has Name property, it's same as a name of field variable, like: MnuBaseFile

            R Offline
            R Offline
            Ralf Meier
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups