views:

162

answers:

2

I have a handler consuming the keyDown event of a WinForms RTB, that has the following code:

GetTextAtLoc(RTB->SelectionStart); // selects some text at the caret's position
RTB->SelectedText = "SomeOfMyOwn";
GetTextAtLoc(RTB->SelectionStart); // selects the replacement string
RTB->SelectionStart += RTB->SelectionLength - 1;

While this code seems to do its job (SelectionStart/Length properties are updated correctly), the caret doesn't move to the end of the new string - It says right where it was at the time of GetTextAtLoc's first call. Redrawing the textbox doesn't seem to have any effect either.

A: 

You did not specify the new length (and is therefor: 1-1=0). Try something like:

SelectionStart += (length("SomeOfMyOwn"))

riffnl
Actually, I did. The second GetTextAtLoc call selects "SomeOfMyOwn" and the subsequent SelectionLength query gets the length of the above literal.
shadeMe
RTB can be a bit "shady" at times with selections;Have you tried the Select method using Select(SelectionStart, SelecitonLength)
riffnl
I haven't. Will do so,
shadeMe
A: 

The problem seems to have fixed itself. Dunno what brought about the change, unfortunately. Closing this thread.

shadeMe