|
-
Jun 23rd, 2002, 06:54 PM
#1
Thread Starter
New Member
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.
-
Jun 23rd, 2002, 07:58 PM
#2
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.
-
Jun 24th, 2002, 09:44 AM
#3
Thread Starter
New Member
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?
-
Jun 24th, 2002, 09:49 AM
#4
Thats what sender is for. sender is the object calling the event. So you can access its properties/methods
sender.Text
-
Jun 24th, 2002, 10:21 AM
#5
Thread Starter
New Member
Thanks
Thanks a lot Cander & hellswraith...
Learning more everyday...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|