Results 1 to 2 of 2

Thread: Responding to Menu click event

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Location
    Brooksville, FL
    Posts
    2

    Question Responding to Menu click event

    I have a 'History' menu on the main menu in myformapp. When the form loads, the menu is populated with menuitems that come from text stored in an array of strings, sCommandArray().

    The menu is populated using a for loop:

    For iCounter = 0 To sCommandArray.GetUpperBound(0)
    .m_mnuCommandHistory.MenuItems.Add(sCommandArray(iCounter), New EventHandler(AddressOf CommandHistoryClick))
    next

    The text of each menuitem is the contents of an array element.

    The event handler, CommandHistoryClick, is declared as follows:

    Private Sub CommandHistoryClick(ByVal Sender As system.object, ByVal e As System.EventArgs) Handles m_mnuCommandHistory.Click

    End Sub

    How do I determine which menuitem is the sender? I want to populate a text box with whichever menuitem is selected.

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    try something like this...
    VB Code:
    1. [COLOR=blue]Private Sub[/color] CommandHistoryClick([COLOR=blue]ByVal[/color] Sender [COLOR=blue]As[/color] system.object, [COLOR=blue]ByVal[/color] e [COLOR=blue]As[/color] System.EventArgs) [COLOR=blue]Handles[/color] m_mnuCommandHistory.Click
    2.  
    3. [COLOR=blue]Dim[/color] Mi [COLOR=blue]As[/color] MenuItem = [COLOR=blue]DirectCast[/color](Sender,MenuItem)
    4. [COLOR=blue]If[/color] Mi.Text = "the text of your menu item" [COLOR=blue]Then[/color]
    5.     [COLOR=green]'/// Do Stuff here.[/color]
    6. [COLOR=blue]End If[/color]
    7.  
    8. [COLOR=blue]End Sub[/color]
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width