|
-
Jan 1st, 2006, 09:25 PM
#1
Thread Starter
Giants World Champs!!!!
ContextMenu - Popup
I am using the following code to display a popup menu for a particular node of a treeview:
VB Code:
Private Sub TreeView1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TreeView1.MouseUp
Dim mnuContextMenu As New ContextMenu()
If e.Button = Windows.Forms.MouseButtons.Right Then
Dim mnuItemNew() As MenuItem = New MenuItem() _
{New MenuItem("Item 1"), _
New MenuItem("Item 2"), _
New MenuItem("Item 3")}
Dim TVWMenu As New ContextMenu(mnuItemNew)
TVWMenu.Show(TreeView1, New Point(e.X, e.Y))
End If
End Sub
My question is how do I have a separator line appear Item 2 and Item 3? How can I tell which item was clicked? I have tried the following code but it didn't work:
VB Code:
Private Sub ContextMenuStrip1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ContextMenuStrip1.Click
MsgBox(ContextMenuStrip1.Text)
End Sub
Thanks
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Jan 1st, 2006, 09:31 PM
#2
Re: ContextMenu - Popup
If you want to place a seperator in a menu you just add an item and make its text a single dash. You handle the Click event of each menu item individually. To create a Click event handler for an item just double-click it (the item, not the menu) in the designer.
-
Jan 1st, 2006, 09:33 PM
#3
Re: ContextMenu - Popup
But if your creating the menu items dynamically then you need to use the AddHandler/RemoveHandler methods.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 1st, 2006, 09:45 PM
#4
Thread Starter
Giants World Champs!!!!
Re: ContextMenu - Popup
 Originally Posted by RobDog888
But if your creating the menu items dynamically then you need to use the AddHandler/RemoveHandler methods.
Rob I found this example here:
VB Code:
Sub TestEvents()
Dim Obj As New Class1
' Associate an event handler with an event.
AddHandler Obj.Ev_Event, AddressOf EventHandler
' Call the method to raise the event.
Obj.CauseSomeEvent()
' Stop handling events.
RemoveHandler Obj.Ev_Event, AddressOf EventHandler
' This event will not be handled.
Obj.CauseSomeEvent()
End Sub
Sub EventHandler()
' Handle the event.
MsgBox("EventHandler caught event.")
End Sub
Public Class Class1
' Declare an event.
Public Event Ev_Event()
Sub CauseSomeEvent()
' Raise an event.
RaiseEvent Ev_Event()
End Sub
End Class
But I can't figure out how to implement could you help me out?
Thanks
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
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
|