.net - 如何在 RichTextBox 中创建上下文菜单

标签 .net vb.net winforms richtextbox contextmenu

我想在 RichTextBox 中创建上下文菜单。当我右键单击 RichTextBox 时,我需要剪切、复制、粘贴选项。

最佳答案

来自Microsoft Docs :

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

关于.net - 如何在 RichTextBox 中创建上下文菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4907627/

相关文章:

c# - 澄清 SQL 和 ADO.net 文字参数规范

.net - 选择唯一的随机数

javascript - 在 asp.net 中自动调整面板中子控件的大小

c# - 检查 richtextbox 上的选定文本是否全部为粗体或混合 [C#]

.net - 静态类是线程安全的吗

c# - MySql C# 插入错误。错误的字符串值 : '\xE1ra'

c# - 我可以内联指定我的显式类型比较器吗?

c# - 如何清空datagridview?

c# - 在 Windows 窗体中显示插入数据异常

c# - 从汇编中获取 MSIL?