Results 1 to 5 of 5

Thread: Passing parameters to menu handler

  1. #1

    Thread Starter
    New Member ourman's Avatar
    Join Date
    Jun 2002
    Location
    Cuba
    Posts
    15

    Question Passing parameters to menu handler

    I had to use menus on a form and corresponding event handlers on the click of menu items like this:

    Code:
    miMaintanence.MenuItems.Add(New MenuItem(strMenuCaption, New EventHandler(AddressOf Me.OpenMaintanenceForm)))
    and later I have:

    Code:
            
    Private Sub OpenMaintanenceForm(ByVal sender As Object, ByVal e As System.EventArgs)
           ' ...some code here
    End Sub
    I will like to pass a parameter to the Sub OpenMaintanenceForm that's is executed after clicking on the Menu Item.

    On this case I will like to pass a string parameter (strFrormCaption) to set the Caption of the Form to be opened. How should I go to do this?
    Thanks.
    Saludos,
    Erich

  2. #2
    hellswraith
    Guest
    I would just make a class (form) variable. Set it to what you want, then just access it inside the event code.

    The other way to do it would get really indepth, and I am not fully sure how to go about it. You would need to inherit the menu class into a new class. Then override the event arguements. And I think you would even have to get into some delegates and stuff.... Much easier the first way.

  3. #3

    Thread Starter
    New Member ourman's Avatar
    Join Date
    Jun 2002
    Location
    Cuba
    Posts
    15
    Thanks for your answer. I'll try to explain myself better:

    The menus are build at runtime using data from a database (one menu for each table on the database). I don't know before hands how many tables (menus) will be and this can be a number from 1 to 20 or +

    What I'm tring to to do is to have the MenuItem caption (strMenuCaption on code) sent to the Sub OpenMaintanenceForm
    and this way I can know which menu was clicked and as a consecuence which table I need to display on the form that opens this Sub.

    I'm thinking on using the (e As System.EventArgs) as it should contain the Menu Item caption..

    What do you think?
    Saludos,
    Erich

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Thats what sender is for. sender is the object calling the event. So you can access its properties/methods


    sender.Text
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    New Member ourman's Avatar
    Join Date
    Jun 2002
    Location
    Cuba
    Posts
    15

    Thanks

    Thanks a lot Cander & hellswraith...

    Learning more everyday...
    Saludos,
    Erich

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