我正在尝试在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从fileinfo添加到图像列表中并显示在树视图中
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;那么问题在哪里呢?!谢谢
发布于 2012-06-19 19:55:44
让我们有一个图像列表属性并将其分配给VirtualStringTree1.Images ImageList1。然后加入前面的评论者,在你使用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;如果这还不够,请发布更多示例代码,以帮助我们了解您的问题。
https://stackoverflow.com/questions/11098822
复制相似问题