trichview.com

trichview.support




Re: ApplyStyleConversion?


Return to index


Author

Message

Sergey Tkachenko

Posted: 04/27/2003 11:34:01


Hi,


You set color of current text to the specified value. But when user click

the editor, current text style is reset to the style of the text at the

position of caret.


Solution: move focus to the editor:


procedure TForm1.Button1Click(Sender: TObject);

var NewStyleNo:integer;

begin

      if ColorDialog1.Execute then begin

        RVE.SetFocus;

        RVE.ApplyStyleConversion(TEXT_COLOR);

      end;

end;




>

> Hi all,

> I cannot change current text color without selecting a item first.

> Here is what I have: a RichViewEdit linked to a RichViewStyle and a button

> which brings up a ColorDialog.

> The idea is that a user click on the button and select a color. After

that,

> all new text he enters into the RichViewEdit at the caret will have the

new

> color.

> It turns out that, if the user first select some text, and then hit the

button

> to change the color, then both the text just selected and text input

afterwards

> will have new color.

> But if the user doesn't select any text, and simply hit the button to

change

> the color, it doesn't have any effect on the color of the new text he

enters

> at the caret.

> There is a demo coming with RichView package called REditor.exe which

includes

> exactly the functionality I want. But after comparing the demo code and

mine,

> I cannot find any difference. I have already change the setting of

RichViewEdit

> to allow adding Style dynamically.

> Could anybody help?

> Thank you.

>

>

> const

>   TEXT_COLOR      = 7;

>

> procedure TForm1.Button1Click(Sender: TObject);

> var NewStyleNo:integer;

> begin

>       ColorDialog1.Execute;

>       RVE.ApplyStyleConversion(TEXT_COLOR);

>

> end;

>

>

> procedure TForm1.RVEStyleConversion(Sender: TCustomRichViewEdit; StyleNo,

>   UserData: Integer; AppliedToText: Boolean; var NewStyleNo: Integer);

> var FontInfo: TFontInfo;

> begin FontInfo := TFontInfo.Create(nil);

>   try

>     FontInfo.Assign(RVStyle1.TextStyles[StyleNo]);

>     case UserData of

>

>       TEXT_COLOR:

>         FontInfo.Color := ColorDialog1.Color;

>     end;

>     NewStyleNo :=

RVStyle1.TextStyles.FindSuchStyle(StyleNo,FontInfo,RVAllFontInfoProperties

> );

>     if NewStyleNo=-1 then begin

>       RVStyle1.TextStyles.Add;

>       NewStyleNo := RVStyle1.TextStyles.Count-1;

>       RVStyle1.TextStyles[NewStyleNo].Assign(FontInfo);

>       RVStyle1.TextStyles[NewStyleNo].Standard := False;

>     end;

>   finally

>     FontInfo.Free;

>   end;

> end;

>

>





Powered by ABC Amber Outlook Express Converter