加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – TVirtualStringTree搜索结果的重点

发布时间:2020-12-15 09:50:41 所属栏目:大数据 来源:网络整理
导读:我想根据搜索条件突出显示VirtualStringTree节点中的文本,例如来自bellow的示例: 有什么建议吗? 解决方法 感谢TLama回答( How to underline or highlight a part of node caption)我调整了一些代码,以便在中间突出显示文本. procedure Tform_main.vt_mainD
我想根据搜索条件突出显示VirtualStringTree节点中的文本,例如来自bellow的示例:

有什么建议吗?

解决方法

感谢TLama回答( How to underline or highlight a part of node caption)我调整了一些代码,以便在中间突出显示文本.

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,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;

祝TLama!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读