Delphi 将小图标添加到virtualtreeview

Delphi 将小图标添加到virtualtreeview,delphi,icons,virtualtreeview,Delphi,Icons,Virtualtreeview,我正在尝试在delphi2010中将小图标添加到VirtualTreeview 我使用属性图像将ImageList附加到VirtualTreeview procedure TMainFrm.VSTGetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean; var ImageIndex: Integer)

我正在尝试在delphi2010中将小图标添加到VirtualTreeview 我使用属性图像将ImageList附加到VirtualTreeview

procedure TMainFrm.VSTGetImageIndex(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
  var Ghosted: Boolean; var ImageIndex: Integer);
var
  FileInfo: PFileInfoRec;
begin
  if Kind in [ikNormal , ikSelected] then
  begin
    if Column = 0 then
    ImageIndex :=ImageList1.AddIcon(FileInfo.FileIco);
  end;
end;
但添加图标后,图标看起来太暗:

文件信息结构(方法记录)在加载文件时填充,因此 我需要的只是将fileinfo中的fileico添加到imagelist中,并显示在treeview中

type
  PFileInfoRec= ^TFileInfoRec;
  TFileInfoRec = record
  strict private
    vFullPath: string;
      .
      .
      .
    vFileIco : TIcon;
  public
    constructor Create(const FilePath: string);
    property FullPath: string read vFullPath;
      .
      .
      .
    property FileIco : TIcon  read vFileIco;
  end;
建造商:

constructor TFileInfoRec.Create(const FilePath: string);
var
  FileInfo: SHFILEINFO;
begin
  vFullPath := FilePath;
    .
    .
    .
  vFileIco        := TIcon.Create;
  vFileIco.Handle := FileInfo.hIcon;
//  vFileIco.Free;
end;

那么问题出在哪里!谢谢

让我们创建一个图像列表
ImageList1
,并将其分配给
VirtualStringTree1.Images
属性。然后加入前面的注释,在使用
FileInfo
之前,为其分配一些内容,例如:
FileInfo:=Sender.GetNodeData(Node)
,而不是使用
FileInfo.FileIco
。但是您应该将图标添加到图像列表中,而不是
OnGetImageIndex
中。您应该在OnInitNode中执行此操作(如果您遵循虚拟范例,您应该执行的操作),而不是将添加图标的索引存储在FileInfo中。例如:

procedure TForm1.VirtualStringTree1InitNode(Sender: TBaseVirtualTree;
  ParentNode, Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
var
  FileInfo: PFileInfoRec;
begin
  FileInfo := Sender.GetNodeData(Node);
  //...
  FileInfo.FileIcoIndex := ImageList1.AddIcon(FileInfo.FileIco);

end;
而不是在
onGetImageIndex

procedure TMainFrm.VSTGetImageIndex(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
  var Ghosted: Boolean; var ImageIndex: Integer);
var
  FileInfo: PFileInfoRec;
begin
  FileInfo := Sender.GetNodeData(Node);
  if Kind in [ikNormal , ikSelected] then
  begin
    if Column = 0 then
    ImageIndex :=FileInfo.FileIcoIndex;
  end;
end;

如果还不够,请发布更多示例代码,让我们了解您的问题。

看起来像是部分透明的问题。也许您需要将图像列表
ColorDepth
设置为
cd32Bit
@DavidHeffernan,谢谢,但仍然不起作用,您到底做了什么?您是什么时候更改
颜色深度的?在创建图像列表后立即。另外,您的真实代码是什么样子的?大概是真正的代码分配了
FileInfo
。如果真的代码是这样的话,那么你发布假代码是令人失望的。如果这是您的真实代码,那么不为
FileInfo
分配任何内容显然是一个问题。并且,您不能每次树视图要求图像索引时都添加新图标。添加图标一次,每次返回相同的图像索引。David有权,在使用virtual TreeView之前,您必须了解虚拟范例。@S.FATEH您已经接受了问题的答案。你添加的代码对我们来说没有任何改变。