Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

context menu problem in vb.net?

Posted on 2013-01-03
2
Medium Priority
?
668 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 86

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

772 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