说明:

(1)命名:

RichTextBox  -> rtxt1

ContextMenuTrip -> cms1

(2)截图:

(3)完整代码:

<span style="font-size:14px;">using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient; namespace Newemployee {
public partial class Frm_ContextMenuTrip : Form {
public Frm_ContextMenuTrip() {
InitializeComponent();
} //加载事件
private void Frm_ContentMenuTrip_Load(object sender, EventArgs e) {
//加载contextMenuTrip的子项
ToolStripItem tsItem;
tsItem = AddContextMenu("复制", cms1.Items, new EventHandler(Fuzhi_click));
tsItem = AddContextMenu("-", cms1.Items, null);
tsItem = AddContextMenu("粘贴", cms1.Items, new EventHandler(Naintie_click));
tsItem = AddContextMenu("-", cms1.Items, null);
tsItem = AddContextMenu("剪切", cms1.Items, new EventHandler(Jiantie_click)); //右键显示的快捷菜单 contextMenuTrip
<strong> <span style="color:#ff0000;">rtxt1.ContextMenuStrip = cms1;</span></strong> } /// <summary>
/// 添加子菜单
/// </summary>
/// <param name="text">要显示的文字,如果为 - 则显示为分割线</param>
/// <param name="cms">要添加到的子菜单集合</param>
/// <param name="callback">点击时触发的事件</param>
/// <returns>生成的子菜单,如果为分隔条则返回null</returns>
ToolStripMenuItem <strong><span style="color:#ff0000;">AddContextMenu</span></strong>(string text, ToolStripItemCollection cms, EventHandler callback) {
if (text == "-") {
ToolStripSeparator tsp = new ToolStripSeparator();
cms.Add(tsp);
return null;
} else if (!string.IsNullOrEmpty(text)) {
ToolStripMenuItem tsmi = new ToolStripMenuItem(text);
if (callback != null) {
tsmi.Click += callback;
}
cms.Add(tsmi);
return tsmi;
}
return null;
} //复制
public void Fuzhi_click(object sender, EventArgs e) {
rtxt1.Copy();
}
//粘贴
public void Naintie_click(object sender, EventArgs e) {
rtxt1.Paste();
}
//剪贴
public void Jiantie_click(object sender, EventArgs e) {
rtxt1.Cut();
} }
}
</span>

版权声明:本文为博主原创文章,未经博主允许不得转载。

RichTextBox 右键显示 ContextMenuTrip 分类: C# 2014-10-16 10:43 337人阅读 评论(0) 收藏的更多相关文章

  1. C/C++中const的用法 分类: C/C++ 2015-07-05 00:43 85人阅读 评论(0) 收藏

    const是C语言的关键字,经C++进行扩充,变得功能强大,用法复杂.const用于定义一个常变量(只读变量),当const与指针,引用,函数等结合起来使用时,情况会变得复杂的多.下面将从五个方面总结 ...

  2. 合并k个已排序的链表 分类: leetcode 算法 2015-07-09 17:43 3人阅读 评论(0) 收藏

    最先想到的是把两个linked lists 合并成一个. 这样从第一个开始一个一个吞并,直到所有list都被合并. class ListNode:# Definition for singly-lin ...

  3. 彩色模型 分类: 图像处理 Matlab 2015-01-08 20:43 364人阅读 评论(0) 收藏

    彩色模型(又称彩色空间或彩色系统)是描述色彩的一种方法,本质上,彩色模型就是坐标系统和子空间的规范,系统中的每种颜色由单个点来表示.下面介绍两种最常用的彩色模型. 一.RGB彩色模型: RGB模型是最 ...

  4. hadoop调优之一:概述 分类: A1_HADOOP B3_LINUX 2015-03-13 20:51 395人阅读 评论(0) 收藏

    hadoop集群性能低下的常见原因 (一)硬件环境 1.CPU/内存不足,或未充分利用 2.网络原因 3.磁盘原因 (二)map任务原因 1.输入文件中小文件过多,导致多次启动和停止JVM进程.可以设 ...

  5. 8大排序算法图文讲解 分类: Brush Mode 2014-08-18 11:49 78人阅读 评论(0) 收藏

    排序算法可以分为内部排序和外部排序,内部排序是数据记录在内存中进行排序,而外部排序是因排序的数据很大,一次不能容纳全部的排序记录,在排序过程中需要访问外存. 常见的内部排序算法有:插入排序.希尔排序. ...

  6. ios UIKit动力 分类: ios技术 2015-07-14 12:55 196人阅读 评论(0) 收藏

    UIkit动力学是UIkit框架中模拟真实世界的一些特性. UIDynamicAnimator 主要有UIDynamicAnimator类,通过这个类中的不同行为来实现一些动态特性. 它一般有两种初始 ...

  7. 【solr专题之二】配置文件:solr.xml solrConfig.xml schema.xml 分类: H4_SOLR/LUCENCE 2014-07-23 21:30 1959人阅读 评论(0) 收藏

    1.关于默认搜索域 If you are using the Lucene query parser, queries that don't specify a field name will use ...

  8. mount命令以及mount ntfs硬盘权限权限与显示的问题 分类: shell ubuntu 2014-11-08 18:29 148人阅读 评论(0) 收藏

    sudo mount -t 文件系统类型 -o 可设置选项 设备路经 访问路经 #常用文件类型如下: iso9660 光驱文件系统, vfat fat/fat32分区, ntfs ntfs分区, sm ...

  9. iOS开源库--最全的整理 分类: ios相关 2015-04-08 09:20 486人阅读 评论(0) 收藏

    youtube下载神器:https://github.com/rg3/youtube-dl 我擦咧 vim插件:https://github.com/Valloric/YouCompleteMe vi ...

随机推荐

  1. ACM YTU 1012 u Calculate e

    u Calculate e Problem Description A simple mathematical formula for e is where n is allowed to go to ...

  2. MFC error C2065: “IDD_DIALOG1” : 未声明的标识符 转载

    error C2065: “IDD_DIALOG1” : 未声明的标识符 1.编译时提示error C2065: “IDD_DIALOG1” : 未声明的标识符 2.错误的可能原因及解决方法如下: 原 ...

  3. js跳转页面方法

      <span id="tiao">3</span><a href="javascript:countDown"></ ...

  4. [CSS]position定位

    CSS position 属性 通过使用 position 属性,我们可以选择 4 种不同类型的定位,这会影响元素框生成的方式. position 属性值的含义: static 元素框正常生成.块级元 ...

  5. MyEclipse使用经验总结

    0.快捷键 ================================================================================ 编辑: Ctrl+Shif ...

  6. 学习Swift -- 析构过程

    析构过程 析构器只适用于类类型,当一个类的实例被释放之前,析构器会被立即调用.析构器用关键字deinit来标示,类似于构造器要用init来标示. 原理 Swift 会自动释放不再需要的实例以释放资源, ...

  7. Test for open live write

    this is test document. this is test document. this is test document. this is test document. this is ...

  8. win32画线考虑去锯齿

    整理日: 2015年2月16日 这几天一直在研究win32 SDk下画线去锯齿,之前一直用的QT的画线接口函数,里面有去锯齿的效果,可是突然项目要求不能用QT的只能用win32 SDK下的GDI画线接 ...

  9. wcf安全

    http://www.cnblogs.com/artech/archive/2011/07/07/customauthorization01.html 安全 http://www.cnblogs.co ...

  10. Yarn应用程序编程实例

    Yarn自带的Application示例程序:DistributedShell 和 UnManaged AM1 DistributedShell ,故名思意,是一个分布式运行shell命令的应用程序, ...