zoukankan      html  css  js  c++  java
  • RichTextBox 右键显示 ContextMenuTrip

    说明:

    (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>



  • 相关阅读:
    面试:第四章:项目介绍
    面试:第八章:SpringMVC、Springboot、Mybatis、Dubbo、Zookeeper、Redis、Elasticsearch、Nginx 、Fastdfs、ActiveMQ
    HDU2021发工资咯:)
    HDU2029Palindromes _easy version
    js的Prototype属性 解释及常用方法
    backgroundposition 用法详细介绍
    递归算法与迭代算法的区别
    CSS Position 定位属性介绍
    JavaScript的事件绑定及深入
    CSS网页中的相对定位与绝对定位
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/4081901.html
Copyright © 2011-2022 走看看