码迷,mamicode.com
首页 > 其他好文 > 详细

RichTextBox实现鼠标右键(剪切,复制,粘贴)功能

时间:2015-08-27 01:58:42      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:

        private static void InitRichTextBoxContextMenu(RichTextBox textBox)

        {

            //创建剪切子菜单

            var cutMenuItem = new System.Windows.Forms.MenuItem("剪切");

            cutMenuItem.Click += (sender, eventArgs) => textBox.Cut();

            //创建复制子菜单

            var copyMenuItem = new System.Windows.Forms.MenuItem("复制");

            copyMenuItem.Click += (sender, eventArgs) => textBox.Copy();

            //创建粘贴子菜单

            var pasteMenuItem = new System.Windows.Forms.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;

        }

RichTextBox实现鼠标右键(剪切,复制,粘贴)功能

标签:

原文地址:http://www.cnblogs.com/zhanglei93/p/4762037.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!