Solved

context menu problem in vb.net?

Posted on 2013-01-03
2
660 Views
Last Modified: 2013-01-03
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.
0
Comment
Question by:developer2012
2 Comments
 

Accepted Solution

by:
developer2012 earned 0 total points
ID: 38741437
Adding event handler a the time of menu item declaration resolved the issue.

 contextMenu1.MenuItems.Add(mnuItemCut)
        AddHandler mnuItemCut.Click, AddressOf Me.mnuItemCut_Click

Open in new window

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 38741449
*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".
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question