[英]delphi 7 TImage and TImageList
let i be integer private 让我是整数私人
the code 代码
procedure TForm1.Image1Click(Sender: TObject);
begin
inc(i);
ImageList1.GetIcon(i mod 4,Image1.Picture.Icon);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
i:=0;
ImageList1.GetIcon(i mod 4,Image1.Picture.Icon);
end;
how do i stretch the icon from the list to fit the size of Image1? 如何从列表中拉伸图标以适合Image1的大小?
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;
Sometimes it is a bit awkward to use Delphi since the extent of cooperation between the VCL and the native Windows API is somewhat unclear. 有时使用Delphi有点尴尬,因为VCL和本机Windows API之间的合作程度有点不清楚。 If the above code doesn't work (I get the feeling it is leaking icons), here is a pure native approach (
uses ImgList, CommCtrl
): 如果上面的代码不起作用(我感觉它是泄漏图标),这里是纯粹的原生方法(
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.