Change line spacing in Runtime

General TRichView support forum. Please post your questions here
Post Reply
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Change line spacing in Runtime

Post by Ceprotec »

[Português]
Como alterar as duas opções marcadas a baixo em tempo de execução?
Obrigado!

[English]
Hi Sergey,
How to change the two options marked below at run time?
Thanks!

Image
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Change line spacing in Runtime

Post by Sergey Tkachenko »

Do you want to change it for the selected paragraphs?

If you use RichViewActions, the simplest way is using TrvActionParagraph without a dialog.

For example, to apply double line spacing:

Code: Select all

rvActionParagraph1.UserInterface := False;
rvActionParagraph1.LineSpacingType := rvlsPercent;
rvActionParagraph1.LineSpacing := 200;
rvActionParagraph1.ValidProperties := [rvpimLineSpacing];
rvActionParagraph1.ExecuteTarget(RichViewEdit1);
rvActionParagraph1.UserInterface := True;


Without RichViewActions, use ApplyParaStyleConversion method + OnParaStyleConversion event, like it is shown in TRichView demo Editors\Editor2\
You need to return the index of paragraph style having the proper values of LineSpacing and LineSpacingType properties.
Ceprotec
Posts: 259
Joined: Thu Oct 28, 2010 6:09 pm
Contact:

Re: Change line spacing in Runtime

Post by Ceprotec »

[Portugues]
Funcionou apenas para o parágrafo selecionado.
Como faço para alterar o todo o texto?

[English]
It only worked for the selected paragraph.
How do I change all the text?
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Change line spacing in Runtime

Post by Sergey Tkachenko »

If you want to make it as an editing operation, select the whole text (call RichViewEdit1.SelectAll), then call the code above.

If you want to make it as a fast not undoable operation, call:
(assuming that RichViewEdit1.Style = RVStyle1)

Code: Select all

RichViewEdit1.ClearUndo;
RichViewEdit1.DeleteUnusedStyles(True, True, True);
for i := 0 to RVStyle1.ParaStyles.Count - 1 do
begin
  RVStyle1.ParaStyles[i]LineSpacingType := rvlsPercent;
  RVStyle1.ParaStyles[i]LineSpacing := 200;
end;
RichViewEdit1.Format;
This code works for TRichView as well, just remove the call of ClearUndo. The call of DeleteUnusedStyles is optional.



If you need to create a new document with specific line spacing, just create items in RVStyle1.ParaStyles with the proper properties, and use their indexes when calling Add methods (like AddNL or AddPicture).
Post Reply