trichview.com

trichview.support




Re: Changing Style of TextStyles at runtime


Return to index


Author

Message

Sergey Tkachenko

Posted: 05/15/2003 18:03:34


Yes, all styles in the document are stored in the collection TextStyles.

If you make changes in item in this collection, it will affect all text of

this style.


If you want to implement command "Make the selected text italic", you need

to use ApplyStyleConversion event (example is in Demos\Delphi\Editors\Editor

2\) or RichViewActions (http://www.trichview.com/resources/actions/)


As I understand from your example, you want to insert a new word in italic,

then switch back to the normal text.


The code may be like this:


var OldStyleNo, ItalicStyleNo: Integer;


// storing the current style index

OldStyleNo := RichViewEditIn.CurTextStyleNo;

// searching for the style like the current one, but italic

ItalicStyleNo :=

  RichViewEditIn.Style.TextStyles.FindStyleWithFontStyle(OldStyleNo,

[fsItalic], [fsItalic]);

// if not found, creating it

if ItalicStyleNo<0 then begin

  RichViewEditIn.Style.TextStyles.Add;

   ItalicStyleNo := RichViewEditIn.Style.TextStyles.Count-1;

   with RichViewEditIn.Style.TextStyles[ItalicStyleNo] do begin

     .Assign(RichViewEditIn.Style.TextStyles[OldStyleNo]);

     Style := Style + [fsItalic];

     Standard := False;

end;

// inserting italic text

RichViewEditIn.ApplyTextStyle(ItalicStyleNo);

RichViewEditIn.InsertText(StripVenturaCodes(DataSetIn.FieldByName('Subhdg').

AsString);

// restoring the original style

RichViewEditIn.ApplyTextStyle(OldStyleNo);




>

> Hello,

>

> I am trying to italicize a word in a paragraph with code like:

>

>   RichViewEditIn.Style.TextStyles[intStyleNum].Style := [fsItalic] ;

>   RichViewEditIn.ApplyTextStyle(intStyleNum);

>   RichViewEditIn.InsertText(DataSetIn.FieldByName('Heading').AsString +

#13,

> False);

>   RichViewEditIn.InsertText('�  ', False);

>

>   // Set text back to normal

>   RichViewEditIn.Style.TextStyles[intStyleNum].Style := [] ;

>   RichViewEditIn.ApplyTextStyle(intStyleNum);

>

RichViewEditIn.InsertText(StripVenturaCodes(DataSetIn.FieldByName('Subhdg').

AsString)

> + #13, False);

>

> But all the text takes on the style of the last value for

>   RichViewEditIn.Style.TextStyles[intStyleNum].Style

>

> What is the proper way to change the TextStyle of words in a paragraph at

> runtime?

>

> Thanks,

> Jeff Luckey

>





Powered by ABC Amber Outlook Express Converter