G
gy87sz
Unregistered / Unconfirmed
GUEST, unregistred user!
求助:關於TreeView構件的使用——當單擊(Click)某個結點(Node)時,該結點的imageindex會自動變成0,如何才能不讓結點的imageindex自動改變?(50分)<br />求助:關於TreeView構件的使用——當單擊(Click)某個結點(Node)時,該結
點的imageindex會自動變成0,如何才能不讓結點的imageindex自動改變?
=====================================================================
unit selectdir;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, imglist, shellApi;
type
TForm2 = class(TForm)
TreeView1: TTreeView;
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
Images:TImageList;
end;
var
Form2: TForm2;
implementation
{$R *.DFM}
procedure TForm2.FormActivate(Sender: TObject);
var treenode1,treenode2:TTreeNode;
tmpicon :TIcon;
begin
tmpIcon:=TIcon.Create;
images:=TImageList.Create(self);
with images do
begin
tmpIcon.Handle:=ExtractIcon(handle,PChar('c:/windows/explorer.exe'),3);
addIcon(tmpIcon);
tmpIcon.Handle:=ExtractIcon(handle,PChar('c:/windows/explorer.exe'),0);
addIcon(tmpIcon);
tmpIcon.Handle:=ExtractIcon(handle,PChar('c:/windows/system/mydocs.dll'),0);
addIcon(tmpIcon);
tmpIcon.Handle:=ExtractIcon(handle,PChar('c:/windows/system/shell32.dll'),6);
addIcon(tmpIcon);
tmpIcon.Handle:=ExtractIcon(handle,PChar('c:/windows/system/shell32.dll'),8);
addIcon(tmpIcon);
tmpIcon.Handle:=ExtractIcon(handle,PChar('c:/windows/system/shell32.dll'),11);
addIcon(tmpIcon);
tmpIcon.Handle:=ExtractIcon(handle,PChar('c:/windows/system/shell32.dll'),3);
addIcon(tmpIcon);
tmpIcon.Handle:=ExtractIcon(handle,PChar('c:/windows/system/shell32.dll'),4);
addIcon(tmpIcon);
end;
tmpIcon.Free;
treeview1.Images:=Images;
// treeview1.StateImages:=Images;
with treeview1.Items do
begin
clear;
treenode1:=add(nil,'桌面');
treenode1.ImageIndex:=0;
treenode2:=addchild(treenode1,'我的電腦');
treenode2.ImageIndex:=1;
treenode2:=addchild(treenode1,'我的文檔');
treenode2.ImageIndex:=2;
end;
end;
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Images.Free;
end;
end.
點的imageindex會自動變成0,如何才能不讓結點的imageindex自動改變?
=====================================================================
unit selectdir;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, imglist, shellApi;
type
TForm2 = class(TForm)
TreeView1: TTreeView;
procedure FormActivate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
Images:TImageList;
end;
var
Form2: TForm2;
implementation
{$R *.DFM}
procedure TForm2.FormActivate(Sender: TObject);
var treenode1,treenode2:TTreeNode;
tmpicon :TIcon;
begin
tmpIcon:=TIcon.Create;
images:=TImageList.Create(self);
with images do
begin
tmpIcon.Handle:=ExtractIcon(handle,PChar('c:/windows/explorer.exe'),3);
addIcon(tmpIcon);
tmpIcon.Handle:=ExtractIcon(handle,PChar('c:/windows/explorer.exe'),0);
addIcon(tmpIcon);
tmpIcon.Handle:=ExtractIcon(handle,PChar('c:/windows/system/mydocs.dll'),0);
addIcon(tmpIcon);
tmpIcon.Handle:=ExtractIcon(handle,PChar('c:/windows/system/shell32.dll'),6);
addIcon(tmpIcon);
tmpIcon.Handle:=ExtractIcon(handle,PChar('c:/windows/system/shell32.dll'),8);
addIcon(tmpIcon);
tmpIcon.Handle:=ExtractIcon(handle,PChar('c:/windows/system/shell32.dll'),11);
addIcon(tmpIcon);
tmpIcon.Handle:=ExtractIcon(handle,PChar('c:/windows/system/shell32.dll'),3);
addIcon(tmpIcon);
tmpIcon.Handle:=ExtractIcon(handle,PChar('c:/windows/system/shell32.dll'),4);
addIcon(tmpIcon);
end;
tmpIcon.Free;
treeview1.Images:=Images;
// treeview1.StateImages:=Images;
with treeview1.Items do
begin
clear;
treenode1:=add(nil,'桌面');
treenode1.ImageIndex:=0;
treenode2:=addchild(treenode1,'我的電腦');
treenode2.ImageIndex:=1;
treenode2:=addchild(treenode1,'我的文檔');
treenode2.ImageIndex:=2;
end;
end;
procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Images.Free;
end;
end.