添加小图标到virtualtreeview [英] add small icon to virtualtreeview

查看:537
本文介绍了添加小图标到virtualtreeview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 程序TMainFrm.VSTGetImageIndex(发件人:TBaseVirtualTree; 
节点:PVirtualNode;种类:TVTImageKind;列:TColumnIndex;
var Ghosted:Boolean; var ImageIndex:Integer);
var
FileInfo:PFileInfoRec;
begin
如果在[ikNormal,ikSelected]中的类型然后
开始
如果Column = 0然后
ImageIndex:= ImageList1.AddIcon(FileInfo.FileIco);
结束
结束

但添加图标看起来太暗之后:





FileInfo Strucutre方法)填充,当我加载文件,所以
我只需要将文件从fileinfo添加到imagelist并显示在treeview

  type 
PFileInfoRec = ^ TFileInfoRec;
TFileInfoRec = record
strict private
vFullPath:string;



vFileIco:TIcon;
public
构造函数Create(const FilePath:string);
属性FullPath:string read vFullPath;



属性FileIco:TIcon读取vFileIco;
结束

构造函数:

 构造函数TFileInfoRec.Create(const FilePath:string); 
var
FileInfo:SHFILEINFO;
begin
vFullPath:= FilePath;



vFileIco:= TIcon.Create;
vFileIco.Handle:= FileInfo.hIcon;
// vFileIco.Free;
结束

所以问题在哪里? !谢谢

解决方案

让我们有一个图片列表 ImageList1 并将其分配给 VirtualStringTree1.Images 属性。然后在使用 FileInfo 之前加入前面的评论者,分配一些东西,如: FileInfo:= Sender.GetNodeData(Node),比您可以使用 FileInfo.FileIco 。但是,您应该将图标添加到不在 OnGetImageIndex 中的图像列表中。您应该在OnInitNode(如果您遵循虚拟范例,您应该做什么),而不是将添加的图标的索引存储在FileInfo中。示例:

 过程TForm1.VirtualStringTree1InitNode(发件人:TBaseVirtualTree; 
父节点,节点:PVirtualNode; var InitialStates:TVirtualNodeInitStates) ;
var
FileInfo:PFileInfoRec;
begin
FileInfo:= Sender.GetNodeData(Node);
// ...
FileInfo.FileIcoIndex:= ImageList1.AddIcon(FileInfo.FileIco);

end;

onGetImageIndex

 程序TMainFrm.VSTGetImageIndex(发件人:TBaseVirtualTree; 
节点:PVirtualNode;种类:TVTImageKind;列:TColumnIndex;
var Ghosted:Boolean; var ImageIndex:Integer);
var
FileInfo:PFileInfoRec;
begin
FileInfo:= Sender.GetNodeData(Node);
如果在[ikNormal,ikSelected]然后
开始
如果Column = 0然后
ImageIndex:= FileInfo.FileIcoIndex;
结束
结束

如果还不够,请发布更多示例代码,以启发我们您的问题。 >

i am trying to add small icon to VirtualTreeview in delphi2010 i have ImageList attached to VirtualTreeview using the property images

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;

but after adding the icons look too dark:

FileInfo Strucutre (Record with methods) filled whene i load the files so what i need is just to add the fileico from fileinfo to imagelist and display in 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;

the constructor:

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

so where is the probleme ? ! thanks

解决方案

Let's have an image list ImageList1 and assign it to VirtualStringTree1.Images property. Then joining to the previous commenters, before you use FileInfo, assign something to it, like: FileInfo := Sender.GetNodeData(Node), than you can use FileInfo.FileIco. But you should add your icon to the imagelist not in the OnGetImageIndex. You should do it in OnInitNode (if you follow the virtual paradigm, what you should do), than store the index of the added icon in FileInfo. example:

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;

than in 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;

If it's not adequate, please post more sample code, to enlighten us about your problem.

这篇关于添加小图标到virtualtreeview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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