C# RichTextBox selection problem

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.

Leave a Comment