Page 1 of 1
add text to the last line?
Posted: Fri Sep 01, 2017 9:06 am
by Vincent
Hi.
I'm using RichViewEdit,
Is there a way to add text to the last line?
Like the signature of a mail.
Thank you for reference link.
Sorry my english.
Best Regared, Vincent.
Re: add text to the last line?
Posted: Fri Sep 01, 2017 11:31 am
by Sergey Tkachenko
If you want to add it when generating document, use AddNL method:
Code: Select all
rv.AddNL('Signature', StyleNo, ParaNo);
rv.Format;
If you want to add it as an editing operation (undoable):
Code: Select all
// moving caret to the end
rv.BeginUndoGroup(rvutInsert);
rv.SetUndoGroupMode(True);
rv.SetSelectionBounds(
rv.ItemCount-1, rv.GetOffsAfterItem(rv.ItemCount-1),
rv.ItemCount-1, rv.GetOffsAfterItem(rv.ItemCount-1));
rv.CurTextStyleNo := StyleNo;
// inserting
rv.InsertText(#13#10'Signature');
rv.ApplyParaStyle(ParaNo);
rv.SetUndoGroupMode(False);
Since this code contains several operations (inserting text and applying paragraph style), I added BeginUndoGroup+SetUndoGroupMode to group them in a single undo item.
This code uses two variables:
- StyleNo defines text properties, index in rv.Style.TextStyles
- ParaNo defines paragraph properties, index in rv.Style.ParaStyles.
Normally, indexes of plain text are zeros (so use StyleNo = ParaNo = 0)