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?
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;
}));
}
Same problem here with RichTextBox in TabControl. It didn't matter if it was created in Designer or dynamically. The solution was, as Roast suggested in the comment below his answer, to use one of the tab events. After setting AutoWordSelection
to False
there, the problem would intermittently return when changing tabs. What fixed that was setting it to True
and then False
in the tab event.
Private Sub TabControl1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TabControl1.SelectedIndexChanged
RichTextBox1.AutoWordSelection = True
RichTextBox1.AutoWordSelection = False
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With