Copy and apply style button

General TRichView support forum. Please post your questions here
Post Reply
retwas
Posts: 39
Joined: Tue May 21, 2013 1:41 pm

Copy and apply style button

Post by retwas »

Hi

Does the button copy/apply style exist ?

Image

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

Post by Sergey Tkachenko »

No, but I can explain how to save formatting and how to apply saved formatting.
Do you use StyleTemplates in your application?
Steku
Posts: 9
Joined: Fri Dec 13, 2013 4:01 pm

Post by Steku »

If you don't mind, I'm interested in how to do that. StyleTemplates are used.

Thanks, steku
retwas
Posts: 39
Joined: Tue May 21, 2013 1:41 pm

Post by retwas »

Yes I use, I'm interessed to know :)
Sergey Tkachenko
Site Admin
Posts: 17602
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I can explain how to store the current text formatting and how to apply it to selected text.
This code stores only text formatting, without paragraph formatting.

You need two variables to store formatting:

Code: Select all

TextStyle: TFontInfo; 
StyleTemplateName: TRVStyleTemplateName;
Storing:

Code: Select all

var ST: TRVStyleTemplate; 

if TextStyle=nil then 
  TextStyle := TFontInfo.Create(nil); 
TextStyle.Assign(RVStyle1.TextStyles[RichViewEdit1.CurTextStyleNo]); 
ST := RVStyle1.StyleTemplates.FindItemById(TextStyle.StyleTemplateId); 
if ST<>nil then 
  StyleTemplateName :=  ST.Name 
else 
  StyleTemplateName :=  '';
Applying:

Code: Select all

var ST: TRVStyleTemplate; 

if TextStyle<>nil then begin 
  TextStyle.ParaStyleTemplateId := RVStyle1.TextStyles[RichViewEdit1.CurTextStyleNo]).ParaStyleTemplateId;  
  ST := RVStyle1.StyleTemplates.FindItemByName(StyleTemplateName); 
  if ST<>nil then 
    TextStyle.StyleTemplateId := ST.Id 
  else 
    TextStyle.StyleTemplateId := -1; 
  RichViewEdit1.ApplyTextStyle(RVStyle1.FindTextStyle(TextStyle)); 
end;
When the form is destroyed:

Code: Select all

TextStyle.Free; 
Post Reply