>
> I’m trying to trim any spaces at the end of a line in a TRichEdit after
> the cursor moves off the line. I can detect when the cursor moves, and
> I can trim the line – the problem is, when I update the line
> (MyRichEdit.Lines[PreviousLine] := MyString) the cursor pops back to the
> line that has been trimmed. Any way to prevent this?
>
You have to save and restore the caret position yourself, e.g.
[code lang=”delphi”]procedure TForm1.Button1Click(Sender: TObject);
var
temp : integer ;
oldlen: integer;
s: string;
begin
with richedit1 do begin
temp:= selstart;
s:= lines[0];
oldlen := Length( S );
S := Trim( S );
lines[0] := S;
selstart := temp – oldlen + length( S );
end;
end;
[/code]
Peter Below (TeamB)
100113.1101@compuserve.com
)
No e-mail responses, please, unless explicitely requested!
[tags]Delphi, Components, RichEdit[/tags]
0 Kommentare zu “Change RichEdit without moving the Cursor”