2012-06-19 20 views
1

我試圖小圖標在delphi2010 我有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; 

連接到VirtualTreeview但增加的圖標後,添加到VirtualTreeview得很暗:

screenshot

FileInfo Strucutre(記錄與方法)填充whene我加載文件,所以 我需要的僅僅是fileico添加到imagelist和d在樹狀isplay

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; 

所以哪裏是probleme? !謝謝

+0

看起來像部分透明的問題。也許你需要將圖像列表'ColorDepth'設置爲'cd32Bit'。 –

+0

@DavidHeffernan謝謝,但仍然無法工作 –

+0

好的,你到底做了什麼?當你改變了'ColorDepth'?立即在創建圖像列表之後。另外,你的真實代碼是什麼樣的?據推測,真正的代碼分配'FileInfo'。如果真實代碼這樣做,那麼你發佈虛假代碼令人失望。如果這是你真正的代碼,那麼不給'FileInfo'分配任何東西顯然是一個問題。 –

回答

2

讓我們有一個圖像列表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; 

如果它不充足,請發佈更多示例代碼,讓我們認識了你的問題。

+0

我添加了更多的代碼... –

+3

@ S.FATEH你已經接受了你的問題的答案。您添加的代碼不會爲我們改變任何內容。 –