Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TVirtualStringTree highlight of searching result

I would like to highlight the text from a node of VirtualStringTree according to search criteria like example from bellow:

enter image description here

Any suggestion please?

like image 270
REALSOFO Avatar asked Apr 29 '15 13:04

REALSOFO


People also ask

What is the difference between tbasevirtualtree and tvirtualstringtree?

Descentant of TBaseVirtualTree which is able to manage node captions on its own. TVirtualStringTree adds no new functionality to TCustomVirtualStringTree but is publicly available version and appears in the component palette.

What is highlighting in Manticore search?

Highlighting allows you to get snippets of search results with matching keywords highlighted. It helps to improve your application’s search experience. You can highlight keywords in text in Manticore Search using several methods.

What are the benefits of highlighting in search results?

You can benefit from search results highlighting if you want to improve readability of search results in your application or a web site. Highlighting allows you to get snippets of search results with matching keywords highlighted. It helps to improve your application’s search experience.

How to highlight search text in textarea or Div using JavaScript?

Using the following steps; you can highlight search text in Textarea or Div using javaScript; as shown below: First of all create a new html file and update the following code into your file: <p>JavaScript is a dynamic computer programming language.


1 Answers

Thanks to TLama answer (How to underline or highlight a part of node caption) I adjust a bit the code in order to highlight the text also in the middle.

procedure Tform_main.vt_mainDrawText(Sender: TBaseVirtualTree;
  TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
  const Text: string; const CellRect: TRect; var DefaultDraw: Boolean);
var
  BackMode, position: Integer;
begin
  // if the just rendered node's Text contain the text written in a TEdit control
  // called Edit, then...
  position:= Pos(AnsiLowerCase(edit_search.Text), AnsiLowerCase(text));
  if position > 0 then
  begin
    // store the current background mode; we need to use Windows API here because the
    // VT internally uses it (so the TCanvas object gets out of sync with the DC)
    BackMode := GetBkMode(TargetCanvas.Handle);
    // setup the color and draw the rectangle in a width of the matching text
    TargetCanvas.Brush.Color := clYellow;
    TargetCanvas.FillRect(Rect(
      CellRect.Left + TargetCanvas.TextWidth(Copy(Text, 1, position-1)),
      CellRect.Top + 3,
      CellRect.Left  + TargetCanvas.TextWidth(Copy(Text, 1, position-1)) + TargetCanvas.TextWidth(Copy(Text, position, Length(edit_search.Text))),
      CellRect.Bottom - 3)
    );
    // restore the original background mode (as it likely was modified by setting the
    // brush color)
    SetBkMode(TargetCanvas.Handle, BackMode);
  end;
end;

Best wishes to TLama!

like image 64
REALSOFO Avatar answered Sep 28 '22 20:09

REALSOFO