add text to the last line?

General TRichView support forum. Please post your questions here
Post Reply
Vincent
Posts: 1
Joined: Fri Sep 01, 2017 8:57 am

add text to the last line?

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: add text to the last line?

Post 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)
Post Reply