How best to render an overlay icon on top of basic Delphi TVirtualTreeView node icon

情到浓时终转凉″ 提交于 2019-12-06 04:53:09

问题


I'm converting a tree view from the standard TTreeView to use TVirtualStringTree. My final challenge is to implement a feature where I need to draw a 'pass/fail' status indicator on top of the known node icon. With TTreeView I used:

  var
   R : TRect;
  begin
    R := Node.DisplayRect( True );
    StatusIconList.Draw( TreeView1.Canvas,
                         R.Left - StatusIconList.Width - 14,
                         R.Top,
                         3 {MyOverlayImageIndex} );

The result is the red cross over the basic icon as shown below:

With TVirtualStringTree I hoped to find either a better way, or to get better known positions for the required overlay icon position. I'm doing:

   procedure DrawFailed;
    var
     R : TRect;
    begin
      R := CellRect;
      StatusIconList.Draw( TargetCanvas,
                           R.Left - StatusIconList.Width + 49 + Sender.GetNodeLevel( Node ) * 16,
                           R.Top,
                           siiFailed );
    end;

Is this the best solution? Is there a better way of getting the top/left corner of the basic icon without the horrible node level call?


回答1:


You get Kind: TVTImageKind parameter in your OnGetImageIndex event handler. Check it for ikOverlay and simply return the appropriate image index.



来源:https://stackoverflow.com/questions/6227636/how-best-to-render-an-overlay-icon-on-top-of-basic-delphi-tvirtualtreeview-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!