Search code examples
c#.netrichtextbox

RichTextBox.AutoWordSelection broken?


I am writing a windows forms application in C# and I create a RichTextBox (via code, not the designer). I am setting the AutoWordSelection property to false, but when I highlight stuff in the box, it still jumps to the boundaries of words, plus a space. Is this a flaw in .NET or am I doing it wrong?


Solution

  • Using .NET 3.5 i still have this issue. This was reported to Microsoft and flagged as a "Wont Fix" in 2005. This is the latest news i can find on the issue.

    Here is the MS Connect bug report: http://connect.microsoft.com/VisualStudio/feedback/details/115441/richtextboxs-autowordselection-property-does-not-work-correctly#details

    Here is a more recent 2010 post about another person who noticed the problem: http://sonicflare.net/2010/01/10/shipped-bug-feature/#more-192

    ----------UPDATE-------------

    I've made it work by placing an extra AutoWordSelection = False in the Form's Load event.

       public Form1()
        {
            InitializeComponent();
            rich = new RichTextBox();
            rich.Size = new Size(150, 50);
            rich.Text = "Ignoring a bug for five years does not make it a undocumented feature.";
            rich.Location = new Point(20, 20);
            rich.AutoWordSelection = false;
            this.Controls.Add(rich);
        }
    
    private void Form1_Load(object sender, EventArgs e)
    {
        this.BeginInvoke(new EventHandler(delegate
        {
            rich.AutoWordSelection = false;
        }));
    }