developer2012
asked on
context menu problem in vb.net?
Hi everyone,
I wrote the below code for context menu in vb.net.
Any bright ideas?
Thank you.
I wrote the below code for context menu in vb.net.
Private Sub InitializeMyContextMenu()
' Create the contextMenu and the MenuItem to add.
Dim contextMenu1 As New ContextMenu()
Dim mnuItemCut As New MenuItem("Cut")
Dim mnuItemCopy As New MenuItem("&Copy")
Dim mnuItemPaste As New MenuItem("&Paste")
' Use the MenuItems property to call the Add method
' to add the MenuItem to the MainMenu menu item collection.
contextMenu1.MenuItems.Add(mnuItemCut)
contextMenu1.MenuItems.Add(mnuItemCopy)
contextMenu1.MenuItems.Add(mnuItemPaste)
' Assign mainMenu1 to the rich text box.
richtxtbox1.ContextMenu = contextMenu1
End Sub
and the below code for copy & paste. Private Sub mnuItemCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuItemCopy.Click
txtSRFormD_Instructions.Copy()
End Sub
Private Sub mnuItemCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuItemCut.Click
txtSRFormD_Instructions.Cut()
End Sub
I got the context menu though but the copy ans cut does not work?Any bright ideas?
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
*Why do you have "Handles mnuItemCopy.Click" on the end of your methods if you are creating them at runtime and using AddHandler?...that would require you to either have "mnuItemCopy" already on the form, or you declared it at the form level using "WithEvents".