procedure TForm1.Image1Click(Sender: TObject);
var
icon: TIcon;
begin
inc(i);
Image1.Canvas.FillRect(ClientRect);
icon := TIcon.Create;
try
ImageList1.GetIcon(i mod 4, icon);
DrawIconEx(Image1.Canvas.Handle, 0, 0, icon.Handle, Image1.Width, Image1.Height, 0, 0, DI_NORMAL);
finally
icon.Free;
end
end;
更好的办法
有时是有点别扭使用Delphi自VCL和本地Windows API之间合作的程度是有些不清楚。如果上面的代码不工作(给我的感觉是漏水的图标),这里是纯天然的方法(uses ImgList, CommCtrl
):
procedure TForm1.Image1Click(Sender: TObject);
var
icon: HICON;
begin
inc(i);
Image1.Canvas.FillRect(ClientRect);
icon := ImageList_GetIcon(ImageList1.Handle, i mod 4, ILD_NORMAL);
try
DrawIconEx(Image1.Canvas.Handle, 0, 0, icon, Image1.Width, Image1.Height, 0, 0, DI_NORMAL);
finally
DestroyIcon(icon);
end
end;
如果你改变了代码,并删除图标:= TIcon.create和线条icon.free;此代码作为魅力并将其标记为答案。 – none 2010-11-29 15:11:26