C# RichTextBox 禁用自动块选择

C# RichTextBox disable auto block selection

我无法在RichTextBox中对文本进行部分选择,如何禁用自动选择?

this.txtMSInput = new System.Windows.Forms.RichTextBox();
this.txtMSInput.DetectUrls = false;
this.txtMSInput.Location = new System.Drawing.Point(6, 31);
this.txtMSInput.Name = "txtMSInput";
this.txtMSInput.Size = new System.Drawing.Size(279, 202);
this.txtMSInput.TabIndex = 43;
this.txtMSInput.Text = "";

找到答案了,这是RichTextBox的bug。

来自

There's a silly bug in the AutoWordSelection property implementation. The workaround is equally silly. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form, replacing the existing RTB.

using System;
using System.Windows.Forms;

public class FixedRichTextBox : RichTextBox {
    protected override void OnHandleCreated(EventArgs e) {
        base.OnHandleCreated(e);
        if (!base.AutoWordSelection) {
            base.AutoWordSelection = true;
            base.AutoWordSelection = false;
        }
    }
}

I left an annotation at the bottom of this MSDN Library page with the details of the bug.