When I use the RichTextBox.Select(int start, int length) function to select text in a rich text box that contains hyperlinks, there is some shift in the selection when I try to select any text that is after the hyperlink.
When I remove the hyperlink, the selection works properly.
Edit: I use RichTextBox 5 (the default in Visual Studio is version 4)
public class RichText50W : RichTextBox
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern IntPtr LoadLibrary(string lpFileName);
protected override CreateParams CreateParams
{
get
{
CreateParams prams = base.CreateParams;
if (LoadLibrary("msftedit.dll") != IntPtr.Zero)
{
prams.ClassName = "RICHEDIT50W";
}
return prams;
}
}
}
The problem occurs only with richtextbox 5+.
These images show the problem and the difference in behavior.
If you try this make sure to set HideSelection property of richtextboxes to "false".
Select functions are displayed on the buttons.
For RTB5, 'e' in "Text" should be selected in the above image.
Apparently RTB5 selects some hidden text.
I need it to select based on the visible text only.
RTB 4 has problems when using tables, so I don't want to use it.
I use .NET 2.0
Edit: To try this in Visual Studio, start with the default richtextbox and change its declaration to RichText50W instead of RichTextBox
Also RichEdit 6 has the same issue.
Thanks