On 08/04/2010 03:04, shoosh wrote:
> In VB.NET, I create a File menu. One of the File Menu items is "Recent
> Projects". Using the following Code, I can add sub-menu items to drop down
> below "Recent Projects."
>
> mnuRecentProjects.DropDownItems.Add("Test Item 4")
> mnuRecentProjects.DropDownItems.Add("Test Item 5")
> mnuRecentProjects.DropDownItems.Add("Test Item 6")
>
> So now at run time I have 3 sub-menu items off my "Recent Projects" menu item.
>
> Question: What event is raised when I click on one of these, say "Test Item
> #4" and how do I access it?
It will be a Click event of some sort, depending on the Type of menu
control you use (MenuItem or ToolStripMenuItem).
If you're creating the menu items manually, use the AddHandler statement
to associate a handling routine with that event, something like:
Private Sub Form_Load() _
Handles MyBase.Load
Dim mi as New MenuItem( "Test Item 3" )
AddHandler mi, AddressOf MenuItem_Click
mnuRecentProjects.DropDownItems.Add( mi )
' IIRC, the ToolStripMenuItem has a constructor to do the
' whole lot in one go.
Dim tmi as New ToolStripMenuItem( "Test Item 4" _
, Nothing _
, AddressOf MenuItem_Click )
mnuRecentProjects.DropDownItems.Add( tmi )
End Sub
.... then ...
Private Sub MenuItem_Click( _
ByVal sender as Object _
, ByVal e as EventArgs _
)
If Not ( typeof sender is MenuItem ) Then
Return
End If
Dim mi as MenuItem = DirectCast( sender, MenuItem )
' mi now contains a reference to the item clicked
End Sub
>
> In VB6 it was simple, in vb.net I can't seem to find how to access the
> underlying code for a sub-menu click event.
>
>
>
>
>
>
>
|