I'm not sure how to get this question to someone at MS but I think I found
an issue with the RichTextBox Control used in VS C# .NET 2.0 (I use
express).
The problem is if there is hidden text at the begining of a line and you try
to select
text that includes that hidden text the Select method does not work.
I have been able to demonstrate this with a very simple app.
Create a form with richTextBox1 and button1 objects and
insert the following code:
private void button1_Click(object sender, EventArgs e)
{
int index = this.richTextBox1.Find("hidden2",
RichTextBoxFinds.MatchCase | RichTextBoxFinds.NoHighlight);
this.richTextBox1.Select(0, index);
int temp = this.richTextBox1.SelectionStart;
int temp2 = this.richTextBox1.SelectionLength;
this.richTextBox1.SelectedText = "Eric";
}
private void Form1_Load(object sender, EventArgs e)
{
//this.richTextBox1.SelectedRtf = @"{\rtf1\ansi te\v hidden1\v0st1\par}";
//this.richTextBox1.SelectedRtf = @"{\rtf1\ansi te\v hidden2\v0st2\par}";
this.richTextBox1.SelectedRtf = @"{\rtf1\ansi\v hidden1\v0test1\par}";
this.richTextBox1.SelectedRtf = @"{\rtf1\ansi\v hidden2\v0test2\par}";
}
Basically what happens is the Select method will have invalid start and
length when
you click the button with the code as it is now. If you use the two lines
of commented
out code to place text in the box instead the selection will work. The only
difference
here is that one set of RTF code has hidden text at the begining of a line
and the
other has it inserted in visible text.
What I have found is that the SelectionStart and SelectionLength parameters
are as
follows after calling Select() with the hidden text at the begining of a
line:
richTextBox1.Select(startPos, selLength)
then
richTextBox1.SelectionStart = startPos + selLength and
richTextBox1.SelectionLength = 0.
Can someone help verify this. I can't create an MFC app to demonstrate this
outside of the framework.
Thanks,
Eric