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?
+2
A:
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;
}));
}
Lily
2010-05-18 20:25:06
The problem is that the text boxes are created dynamically in the program. If you can imagine, every time a user adds a tab to a TabControl that I have in my form, the tab comes equipped with a RichTextBox. Can it be fixed in this case?
Nilbert
2010-05-18 21:07:46
Perhaps try to do this in one of the tab events. I believe the key would be to set the property on a different thread than the one it is created on. Also note, while your drag and drop selection works on my fix, double clicking a word still selects it.
Lily
2010-05-19 13:04:46