RichTextBox Question

B

Beringer

I am using Framework v1.0 (C#).
My question about richtextboxes is:
I have been choosing a location in the text box string doing the following:
....
textbox.SelectionLength = 0;
textbox.SelectionStart = myPos;
....
After setting the position I have been inserting text by calling:
....
textbox.SelectedText = "Testing";
....

I discovered that the new SelectionStart after using SelectedText is: myPos
+ 7. 7 being the length of the selected text inserted. This has worked
well for me but it has been brought to my attention that this might be a bug
in the RichTextBox and I shouldn't rely on this and SelectionStart should
really be myPos after using SelectedText. Is this true?

I find this to be very useful because if I use SelectedText again say:
....
textbox.SelectedText = "NewString";
....

The result would be:
"TestingNewString "
and not
"NewStringTesting"

It seems very natural to move the SelectionStart after using SelectedText,
am I wrong?

Thanks in advance,
Eric
 
M

Morten Wennevik

Hi Eric,

I haven't heard anything about this being a bug, and the behaviour is also
found in regular TextBoxes and in all version of Framework. I suppose you
could argue that selectionstart should remain where it is set, but since
it follows the cursor I find it logical that it should move when you
insert text as well. Perhaps SelectionLength should be set to the length
of inserted text instead. *Ponder*

In any case, since this behaviour has been around for so long it is highly
unlikely that it will be changed as that would break older code. Also,
since Microsoft appears to strive to prevent compiler options telling
which command set you should compile against (as pre/post java 1.4) I
don't see it happen.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top