1.Load 事件中注册鼠标点击事件:
(wnText1.OriginControl as WnTextEditorBase).TextEdit.MouseClick += WnFormDemo_MouseClick;
2.拷贝一下方法:
private static void InitRichTextBoxContextMenu(RichTextBox textBox)
{
//创建剪切子菜单
var cutMenuItem = new MenuItem("剪切");
cutMenuItem.Click += (sender, eventArgs) => textBox.Cut();
//创建复制子菜单
var copyMenuItem = new MenuItem("复制");
copyMenuItem.Click += (sender, eventArgs) => textBox.Copy();
//创建粘贴子菜单
var pasteMenuItem = new MenuItem("粘贴");
pasteMenuItem.Click += (sender, eventArgs) => textBox.Paste();
//创建右键菜单并将子菜单加入到右键菜单中
var contextMenu = new ContextMenu();
contextMenu.MenuItems.Add(cutMenuItem);
contextMenu.MenuItems.Add(copyMenuItem);
contextMenu.MenuItems.Add(pasteMenuItem);
textBox.ContextMenu = contextMenu;
}
3.调用
private void WnFormDemo_MouseClick(object sender, MouseEventArgs e)
{
InitRichTextBoxContextMenu((wnText1.OriginControl as WnTextEditorBase).TextEdit);
}