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
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
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
*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".
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!