Re: runtime menu & handler
vb Code:
AddHandler MainMenufirstsub1.Click, AddressOf MainMenufirstsub1_Click
Private Sub MainMenufirstsub1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'your menu code here
End Sub
you can use the sender argument to determine which menu was clicked
Re: runtime menu & handler
im a little confused by this runtime menu
i tried what you said
Code:
AddHandler MainMenufirstsub1.Click, AddressOf MainMenufirstsub1_Click
and i get name MainMenufirstsub1_Click is not declared
no matter what i put for adress of its not declared
so if my mainmenufirstsub is the one i want to click then this should be right?
im lost
Re: runtime menu & handler
Quote:
Originally Posted by .paul.
vb Code:
AddHandler MainMenufirstsub1.Click, AddressOf MainMenufirstsub1_Click
Private Sub MainMenufirstsub1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'your menu code here
End Sub
you can use the sender argument to determine which menu was clicked
you need to add the sub as shown above. you can use the same handler for more than 1 menuitem, + you use the sender argument to determine which menu was clicked
Re: runtime menu & handler
Quote:
you can use the same handler for more than 1 menuitem, + you use the sender argument to determine which menu was clicked
could ya give me an example of how i could do that, because thats what i want to be able to do
ya i should have known about the sub. for some reason i thought i could find it in the declarations.
thx
Re: runtime menu & handler
this adds 10 menuitems + displays a msgbox when you click on them
vb Code:
for x as integer = 1 to 10
Dim MainMenufirstsub1 As ToolStripMenuItem = New ToolStripMenuItem
MainMenufirstsub1.Text = "Menu" & x.tostring
MainMenufirstsub1.tag = x
MainMenufile1.DropDownItems.Add(MainMenufirstsub1)
AddHandler MainMenufirstsub1.Click, AddressOf MainMenufirstsub1_Click
next
Private Sub MainMenufirstsub1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
msgbox "you clicked menu" & directcast(sender, menuitem).tag
end Sub