|
-
Feb 3rd, 2008, 12:00 PM
#1
Thread Starter
Lively Member
runtime menu & handler
im creating a runtime menu and im trying to add a click event to them, but i need help
Code:
Dim WithEvents mnuSubItem As Menu
Code:
Me.Controls.Add(myMenu)
Code:
Dim MainMenufile1 As ToolStripMenuItem = New ToolStripMenuItem
MainMenufile1.Text = "File"
now for a sub menu that i want to click on i have
Code:
Dim MainMenufirstsub1 As ToolStripMenuItem = New ToolStripMenuItem
MainMenufirstsub1.Text = "Clear"
myMenu.Items.Add(MainMenufile1)
MainMenufile1.DropDownItems.Add(MainMenufirstsub1)
AddHandler MainMenufirstsub1.Click, AddressOf MainMenufirstsub1.Click ?
the menu works fine but, i cant seem to get the handler to work correcty
thx
-
Feb 3rd, 2008, 12:08 PM
#2
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 3rd, 2008, 01:05 PM
#3
Thread Starter
Lively Member
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
-
Feb 3rd, 2008, 01:10 PM
#4
Re: runtime menu & handler
 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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 3rd, 2008, 01:21 PM
#5
Thread Starter
Lively Member
Re: runtime menu & handler
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
Last edited by mrsirpoopsalot; Feb 3rd, 2008 at 01:24 PM.
-
Feb 3rd, 2008, 01:53 PM
#6
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
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
|