C#如何让鼠标右键出现复制把选择的内容复制? 想做个在richTextBox中以蓝色选中区按下鼠标右键提示复制,并点下复制进行复制.谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用contextMenuStrip控件..写个‘复制’后双击产生事件..再在后台写复制代码,最后在到richTextBox属性中的contextMenuStrip选择你用的这个contextMenuStrip控件就OK了 Form1.Designer.csnamespace WindowsApplication15{ partial class Form1 { /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// 清理所有正在使用的资源。 /// </summary> /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.contextMenuStrip1.SuspendLayout(); this.SuspendLayout(); // // richTextBox1 // this.richTextBox1.ContextMenuStrip = this.contextMenuStrip1; this.richTextBox1.Location = new System.Drawing.Point(12, 12); this.richTextBox1.Name = "richTextBox1"; this.richTextBox1.Size = new System.Drawing.Size(280, 254); this.richTextBox1.TabIndex = 0; this.richTextBox1.Text = "这里是内容,请选中再右键点复制"; // // contextMenuStrip1 // this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ToolStripMenuItem}); this.contextMenuStrip1.Name = "contextMenuStrip1"; this.contextMenuStrip1.Size = new System.Drawing.Size(95, 26); // // ToolStripMenuItem // this.ToolStripMenuItem.Name = "ToolStripMenuItem"; this.ToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.ToolStripMenuItem.Text = "复制"; this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.richTextBox1); this.Name = "Form1"; this.Text = "Form1"; this.contextMenuStrip1.ResumeLayout(false); this.ResumeLayout(false); } #endregion private System.Windows.Forms.RichTextBox richTextBox1; private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem; }}Form1.csusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WindowsApplication15{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void ToolStripMenuItem_Click(object sender, EventArgs e) { richTextBox1.Copy(); //将选择文本复制到剪切板 } }} 如何winform获得鼠标在文本框时的状态。。。 如何使用 axShockwaveFlash 播放FLV Socket中的Accept方法 求四舍五入的写法 如何实现pdf文件的预览功能 多线程字段错误 绑定dataSet中的数据到dataGrid中怎么还需要展开啊? 一本专讲MSIL的书名忘记了,请告诉我好吗? win8如何用鼠标右键调用相机并把刚拍的照片移动到当前文件 VS2013 创建虚拟目录 http://localhost: 失败,错误: 文件名: redirection.config 通过IE打开本地程序的问题 Asp.net+Winform管理员评论审核
属性中的contextMenuStrip选择你用的这个contextMenuStrip控件就OK了
namespace WindowsApplication15
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows 窗体设计器生成的代码 /// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.contextMenuStrip1.SuspendLayout();
this.SuspendLayout();
//
// richTextBox1
//
this.richTextBox1.ContextMenuStrip = this.contextMenuStrip1;
this.richTextBox1.Location = new System.Drawing.Point(12, 12);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(280, 254);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "这里是内容,请选中再右键点复制";
//
// contextMenuStrip1
//
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ToolStripMenuItem});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(95, 26);
//
// ToolStripMenuItem
//
this.ToolStripMenuItem.Name = "ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.ToolStripMenuItem.Text = "复制";
this.ToolStripMenuItem.Click += new System.EventHandler(this.ToolStripMenuItem_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.richTextBox1);
this.Name = "Form1";
this.Text = "Form1";
this.contextMenuStrip1.ResumeLayout(false);
this.ResumeLayout(false); } #endregion private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem;
}
}Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplication15
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Copy(); //将选择文本复制到剪切板
}
}
}