Highlight Paragraph Substring

General TRichView support forum. Please post your questions here
Post Reply
lfarkas
Posts: 1
Joined: Tue Oct 18, 2005 10:37 am

Highlight Paragraph Substring

Post by lfarkas »

Hello Sergey,

I have to highlight some special words when user types them into the editor immediately, but I do not want to modify the user defined style.
I have tried the Search&Mark demo, but it modifies the Style so it does not help.

For example: BLABLA BLABLA SPECIALFIELD BLABLA BLABLA

I would like to draw custom background for SPECIALFIELD text, and keep the original style of rest of them. I am playing with the OnDrawTextBack of TRVStyle. It looks like this is what I need. The Left, Top... params contain information about the whole string, and I was not able to find out how to determine the exact position of the SPECIALFIELD word in the RichEdit control.

Is it possible to calculate it any way?

Thanks,
Lajos Farkas

My code is here:

procedure Tfrm_Main.RVEditorStyleDrawTextBack(Sender: TRVStyle; Canvas: TCanvas; StyleNo, Left, Top, Width, Height: Integer; DrawState: TRVTextDrawStates; var DoDefault: Boolean);
Var
I: Integer;
ItemText: String;
ItemTag: Integer;
Begin
ItemText:=TCustomRVFormattedData(Sender.RVData).GetItemText(Sender.ItemNo );
If ItemText='' Then Exit;

If FHelpStorage.LiveTextList.IsValidField( ItemText ) Then
Begin
Canvas.Brush.Color:=clLime;
Canvas.Brush.Style:=bsSolid;
Canvas.Pen.Style:=psSolid;
Canvas.Pen.Color:=clLime;
Canvas.Rectangle( Left, Top, Left + Width, Top + Height);
End;
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

On OnDrawTextBack you do not know which part of text is drawn (in case of multiline text),
It's better to use OnDrawStyleText. You can use Canvas.TextWidth to find the position of substring (if you do not support bidirected text in your application)
Post Reply