471,337 Members | 1,133 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

RichTextBox bug?

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

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
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

richTextBox1.Select(startPos, selLength)
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.

Feb 3 '06 #1
0 1620

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by nouno | last post: by
3 posts views Thread by kangoo | last post: by
1 post views Thread by Nathan Carroll | last post: by
12 posts views Thread by M O J O | last post: by
9 posts views Thread by James Wong | last post: by
3 posts views Thread by michael sorens | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.