RichTextBox 关于cory/paste的bug,该如何解决?vs2005英文版Please follow the steps:
1. select the text in the 2nd richtextbox and hit 'Ctrl-C' to copy
2. click the 'ClearA' button to set the text of  the 2nd richtextbox to ""
3. focus on the 1st richtextbox and hit 'Ctrl-V'
4 you will find that you can't paste it.
Please follow the steps:
1. select the text in the 2nd richtextbox and hit 'Ctrl-C' to copy
2. click the 'ClearB' button to set the text of  the 2nd richtextbox to " "
3. focus on the 1st richtextbox and hit 'Ctrl-V'
4 This time, you can paste it as expection.I guess this is a bug from the RichTextBox control.
And this issue appears only when the text is not english words( such as Chinese Words).Code:
Form1.Designer.cs
namespace richtextboxbug
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }        #region Windows Form Designer generated code        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.richTextBox1 = new System.Windows.Forms.RichTextBox();
            this.richTextBox2 = new System.Windows.Forms.RichTextBox();
            this.button1 = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.button2 = new System.Windows.Forms.Button();
            this.label4 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // richTextBox1
            // 
            this.richTextBox1.ImeMode = System.Windows.Forms.ImeMode.On;
            this.richTextBox1.Location = new System.Drawing.Point(12, 27);
            this.richTextBox1.Name = "richTextBox1";
            this.richTextBox1.Size = new System.Drawing.Size(297, 96);
            this.richTextBox1.TabIndex = 0;
            this.richTextBox1.Text = "";
            this.richTextBox1.TextChanged += new System.EventHandler(this.richTextBox1_TextChanged);
            // 
            // richTextBox2
            // 
            this.richTextBox2.ImeMode = System.Windows.Forms.ImeMode.On;
            this.richTextBox2.Location = new System.Drawing.Point(12, 158);
            this.richTextBox2.Name = "richTextBox2";
            this.richTextBox2.Size = new System.Drawing.Size(297, 96);
            this.richTextBox2.TabIndex = 1;
            this.richTextBox2.Text = "我们的家园";
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(72, 283);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(100, 34);
            this.button1.TabIndex = 2;
            this.button1.Text = "ClearA";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(346, 27);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(433, 102);
            this.label1.TabIndex = 3;
            this.label1.Text = resources.GetString("label1.Text");
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(12, 7);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(27, 17);
            this.label2.TabIndex = 4;
            this.label2.Text = "1st";
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(12, 138);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(32, 17);
            this.label3.TabIndex = 5;
            this.label3.Text = "2nd";
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(197, 283);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(101, 34);
            this.button2.TabIndex = 6;
            this.button2.Text = "ClearB";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(346, 158);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(437, 85);
            this.label4.TabIndex = 7;
            this.label4.Text = resources.GetString("label4.Text");
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label5.ForeColor = System.Drawing.Color.Red;
            this.label5.Location = new System.Drawing.Point(276, 338);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(464, 34);
            this.label5.TabIndex = 8;
            this.label5.Text = "I guess this is a bug from the RichTextBox control.\r\nAnd this issue appears only " +
                "when the text is not english words.";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(807, 405);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.richTextBox2);
            this.Controls.Add(this.richTextBox1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);
            this.PerformLayout();        }        #endregion        private System.Windows.Forms.RichTextBox richTextBox1;
        private System.Windows.Forms.RichTextBox richTextBox2;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Label label5;
    }
}

解决方案 »

  1.   

    Form1.csusing System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace richtextboxbug
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            } 
            private void button1_Click(object sender, EventArgs e)
            {
                //NOTE: this sentence is the real reason for this ctrl-c/v issue
                richTextBox2.Text = "";
            }        private void button2_Click(object sender, EventArgs e)
            {
                richTextBox2.Text = " ";
            }       
        }
    }
      

  2.   

    大家试一下:
    1。建立一个winform,然后在上面画2个richtextbox和一个button1
    2。 
    private void button1_Click(object sender, EventArgs e)
            {
                //NOTE: this sentence is the real reason for this ctrl-c/v issue
                richTextBox1.Text = "";
            }3, 运行这个程序
    4. 在第一个richtextbox1中输入几个中文字,用鼠标选中,按ctrl-c
    5.点击按钮button1,清掉richTextBox1中的text
    6.鼠标焦点置于richtextbox2, 按ctrl-V试图粘贴,但是,一会发现paste不了。救命嘎!!!!