如何在TVirtualStringTree的列中显示图标或图像? [英] How to display an icon or image in a column of TVirtualStringTree?

查看:119
本文介绍了如何在TVirtualStringTree的列中显示图标或图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Delphi VCL项目中,我创建了一个具有两列的简单TVirtualStringTree.第一列将包含标识所表示数据的Name的文本.数据记录还包含一个状态字段.第二列旨在使用不带文字的图像(16x16像素)表示记录的状态.

In a Delphi VCL project, I have created a simple TVirtualStringTree with two columns. The first column will contain text identifying the Name of the data being represented. The data record also contains a status field. The second column is intended to represent the status of the record using an image (16x16 pixel) w/o text.

我已经搜索了演示,但是还没有掌握VTV如何显示节点的完整过程,也没有成功地使图标显示在指定列的节点中.

I have searched demos, but have not mastered the full process for how VTV displays a node, and have not been successful in getting an icon to display in the node of a specified column.

所以我有三个相关的问题:

So I have three related questions:

  1. 我看到在OnGetText事件中如何分配文本,但是我应该在哪里分配或更改图像以反映记录中的当前状态?

  1. I see how the text is assigned in the OnGetText event, but where should I assign or change the image to reflect the current status in my record?

如何使图像实际显示在列中?

How do I get the image to actually display in the column?

我的图像尺寸是否受到限制,或者它们是否可以大于图标?如果是这样,我是否需要更改任何设置来调整每行的高度(如果可能)?

Am I limited in size for the images, or can they be larger than icons? If so, do I need to change any settings to adjust the height of each row (if possible)?

推荐答案

您需要将TImageList分配给您(根据情况为16x16)TVirtualStringTree.Images属性,然后处理事件OnGetImageIndex例如:

You need to assign (16x16 in your case) TImageList to the TVirtualStringTree.Images property, then handle the event OnGetImageIndex e.g.:

procedure TForm1.VirtualStringTree1GetImageIndex(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
  var Ghosted: Boolean; var ImageIndex: Integer);
var
  NodeRec: PNodeRec;
begin
  NodeRec := Sender.GetNodeData(Node);
  if Assigned(NodeRec) then 
  begin
    if (Column = 1) then
    begin 
      if Kind in [ikNormal, ikSelected] then
      begin
        case NodeRec.Status of // check the needed status(es)
          1: ImageIndex := 1; // whichever image you need
          2: ImageIndex := 2; // whichever image you need
          // ...
        end; 
      end;
    end;
  end;
end;

我的图像尺寸受限制吗?或者它们可以比图标大吗? 如果是这样,我是否需要更改任何设置来调整每个的高度 行(如果可能)

Am I limited in size for the images, or can they be larger than icons? If so, do I need to change any settings to adjust the height of each row (if possible)

不知道这是什么意思,因为您表示需要16x16的图像.如果需要不同可能具有不同尺寸的图像列表,则可以使用OnGetImageIndexEx.对于可变高度,您可以在TreeOptions.MiscOptions中设置toVariableNodeHeight并处理OnMeasureItem事件.将图形绘制到VTV画布中的另一种方法是处理例如OnBeforeItemPaint/OnAfterItemPaint.

Not sure what you meant by that, because you stated you need a 16x16 images. You could use OnGetImageIndexEx if you need different image lists with possibly different dimensions. for variable height you could set toVariableNodeHeight in the TreeOptions.MiscOptionsand handle the OnMeasureItem event. another way to draw graphics into the VTV canvas is to handle the OnBeforeItemPaint/OnAfterItemPaint for example.

这篇关于如何在TVirtualStringTree的列中显示图标或图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆