Getting the text of a selected menustrip item

bjwade62

Well-known member
Joined
May 25, 2006
Messages
50
Programming Experience
3-5
Does anyone know how to get the text of a selected menustrip item?


Here's a poor representation of a menu strip item, but you get the idea.

File
|
Open

I'm looking for a way to get the text "Open" from the menuitem.
 
If you're thinking about getting the text when the item is clicked then you can do this:
VB.NET:
[SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] HelloToolStripMenuItem_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) _
[/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] HelloToolStripMenuItem.Click
  MsgBox([/SIZE][SIZE=2][COLOR=#0000ff]DirectCast[/COLOR][/SIZE][SIZE=2](sender, ToolStripMenuItem).Text)
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]
Two other options is using the ItemClicked event of the Menustrip to catch any main menu item clicked, or the DropDownItemClicked of a main menu item to catch any direct child menu item clicked. But each menu item individually have to its own 'private' click event that can be used like the example above.
 
Back
Top