如何在富文本框中创建上下文菜单

时间:2011-02-05 15:16:55

标签: .net vb.net winforms richtextbox contextmenu

如何在富文本框中创建上下文菜单。当我右键单击富文本框

时,我想要剪切,复制,粘贴选项

2 个答案:

答案 0 :(得分:3)

来自MSDN

Private Sub InitializeMyContextMenu()
     ' Create the contextMenu and the MenuItem to add.
     Dim contextMenu1 As New ContextMenu()
     Dim menuItem1 As New MenuItem("C&ut")
     Dim menuItem2 As New MenuItem("&Copy")
     Dim menuItem3 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(menuItem1)
     contextMenu1.MenuItems.Add(menuItem2)
     contextMenu1.MenuItems.Add(menuItem3)

     ' Assign mainMenu1 to the rich text box.
     richTextBox1.ContextMenu = contextMenu1
 End Sub

答案 1 :(得分:-1)

本文介绍如何在运行时使用文本框添加上下文菜单,您也可以使用富文本框实现此功能。试试这个 http://www.authorcode.com/add-contextmenu-with-cutcopy-and-paste-options-to-textbox-in-vb-net/