Setting ShortCut property for MenuItems

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • genojoe

    #1

    Setting ShortCut property for MenuItems

    I have a table (about 50 rows that populate the variables shown below in
    lines 1 and 2) of shortcuts that I would like to read into a Windows Form.
    The following code would work with one big exception:

    CType will not convert a string to a MenuItem. (Line 3)

    Dim MyShortCut As Integer = 13122 '13122 is integer for Ctrl2
    Dim MyMenuItem As String = "MenuItem12 "
    Dim oMnu As Windows.Forms.M enuItem = CType(MyMenuIte m,
    Windows.Forms.M enuItem)
    Dim oSC As Windows.Forms.S hortcut = CType(MyShortCu t,
    Windows.Forms.S hortcut)
    oMnu.Shortcut = oSC

    Is there a way to read and dynamically set this property from a table using
    a different approach?
  • tomb

    #2
    Re: Setting ShortCut property for MenuItems

    genojoe wrote:
    [color=blue]
    >I have a table (about 50 rows that populate the variables shown below in
    >lines 1 and 2) of shortcuts that I would like to read into a Windows Form.
    >The following code would work with one big exception:
    >
    >CType will not convert a string to a MenuItem. (Line 3)
    >
    > Dim MyShortCut As Integer = 13122 '13122 is integer for Ctrl2
    > Dim MyMenuItem As String = "MenuItem12 "
    > Dim oMnu As Windows.Forms.M enuItem = CType(MyMenuIte m,
    >Windows.Forms. MenuItem)
    >
    >[/color]
    Try this:

    Dim oMnu as New Windows.Forms.M enuItem(MyMenuI tem, MyEventHandler,
    MyShortcut)

    or, set the shortcut after just setting the text.

    Tom
    [color=blue]
    > Dim oSC As Windows.Forms.S hortcut = CType(MyShortCu t,
    >Windows.Forms. Shortcut)
    > oMnu.Shortcut = oSC
    >
    >Is there a way to read and dynamically set this property from a table using
    >a different approach?
    >
    >[/color]

    Comment

    • genojoe

      #3
      Re: Setting ShortCut property for MenuItems

      I could not make it work. Thanks for the effort.

      "tomb" wrote:
      [color=blue][color=green]
      > >[/color]
      > Try this:
      >
      > Dim oMnu as New Windows.Forms.M enuItem(MyMenuI tem, MyEventHandler,
      > MyShortcut)
      >
      > or, set the shortcut after just setting the text.
      >
      > Tom
      >
      >[/color]

      Comment

      Working...