Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

context menu problem in vb.net?

Posted on 2013-01-03
2
Medium Priority
?
665 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

721 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