RichTextBox bug?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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


.



Relevant Pages

  • Re: JTexPane: Cross-platform chaos
    ... > which caret and selection positions refer to). ... private AbstractDocument doc; ... private int start; ... public void insertNewText{ ...
    (comp.lang.java.gui)
  • Order of Events with JTable
    ... selection box based on what record number is selected (in order to test ... public void valueChanged{ ... int selectedRow = lsm.getMinSelectionIndex ... If all column heads are wider than the column's cells' ...
    (comp.lang.java.programmer)
  • Re: Bug in list of matrics represended as arays.....
    ... Menu selection: File/New... ... Put a tick in the "Disable language extensions" checkbox ... void display(int *p, int m, int n) ... Richard Heathfield ...
    (comp.lang.c)
  • Re: Block Selection
    ... and one more thing text components support block selection by default that is true but when you want to make editor kind of thing you need to have something that helps you to rectangle selection which is not selection.. ... public void copy{ ... int cnt = selections.length; ... catch (Exception ex) { ...
    (comp.lang.java.gui)
  • RE: Deleting/overwriting highlighted text
    ... Go to Tools>Options>Edit and put a check in the box for 'Typing replaces ... selection'. ... > pressing backspace puts the cursur at the begining of the word. ...
    (microsoft.public.word.docmanagement)