Link to home
Start Free TrialLog in
Avatar of developer2012
developer2012

asked on

context menu problem in vb.net?

Hi everyone,

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

Open in new window

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

Open in new window

I got the context menu though but the copy ans cut does not work?

Any bright ideas?

Thank you.
ASKER CERTIFIED SOLUTION
Avatar of developer2012
developer2012

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike Tomlinson
*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".