PC Review


Reply
Thread Tools Rate Thread

Determining which Menu Item is Clicked

 
 
Elliot
Guest
Posts: n/a
 
      10th Mar 2005
The code creates two menu items at runtime and I want to be know which
menu item was clicked in the Menuitems_Click procedure.
Sender.Gettype.Name returns the value "MenuItem" only.

Any help is appreciated.


Private Sub

Dim mainMenu1 As New MainMenu()

Me.Menu = mainMenu1

' Create empty menu item objects.
Dim menuItem1 As New MenuItem("&File")
Dim menuItem2 As New MenuItem("&Edit")

' Add the menu items to the main menu.
mainMenu1.MenuItems.Add(menuItem1)
mainMenu1.MenuItems.Add(menuItem2)

' Add functionality
AddHandler menuItem1.Click, AddressOf Menuitems_Click
AddHandler menuItem2.Click, AddressOf Menuitems_Click

End Sub

Private Sub Menuitems_Click(ByVal sender As Object, ByVal e As
EventArgs)

' Code to determine which item was clicked -- menuitem1 or menuitem2.

End Sub

 
Reply With Quote
 
 
 
 
Chris Dunaway
Guest
Posts: n/a
 
      10th Mar 2005
that's what the sender argument of the event handler is for. It tells
you which object raised the event. You could check it this way:

If sender Is menuItem1 Then
'bla bla
Else
If sender is MenuItem2 Then
End If
End If


You might also try this, but I'm not sure if it is considered a best
practice:

Select Case True
Case sender Is MenuItem1
Case sender Is MenuItem2
End Select

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determining what menu item called a macro Stephen Lloyd Microsoft Excel Programming 6 6th Aug 2008 01:48 PM
Newbie Q: How to determine WHICH item was clicked on context menu Rex Microsoft C# .NET 6 3rd Aug 2007 04:40 PM
How to determine which dynamic menu item was clicked? Dean Slindee Microsoft VB .NET 1 8th Jul 2007 04:11 PM
Dynamic menu and item clicked William LaMartin Microsoft Dot NET Compact Framework 2 26th Dec 2006 03:27 PM
in a excel file, how to make a menu item for the .xls file that when clicked on it runs myform.show? example plz Daniel Microsoft Excel Worksheet Functions 1 7th Jul 2005 03:52 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:01 AM.