读书人

从绘控件时调用资源图片哪种好一点

发布时间: 2013-01-01 14:04:19 作者: rapoo

自绘控件时,调用资源图片哪种好一点


private
{ Private declarations }
Png:TPngImage;



constructor TMyAppButton.Create(AOwner: TComponent);
begin
Png:=TPngImage.Create;
Png.LoadFromResourceName(HInstance,'app_button');
inherited;
Width:=Png.Width;
Height:=Png.Height

end;

destructor TMyAppButton.Destroy;
begin
FreeAndNil(png);
inherited;
end;

procedure TMyAppButton.paint;
var
R:TRect;
begin
R := ClientRect;
Canvas.Brush.Style := bsClear;
if (FInButtonArea = True)then
begin
Canvas.StretchDraw(R,Png);
end;
end;




private
{ Private declarations }
Png:TPngImage;



constructor TMyAppButton.Create(AOwner: TComponent);
begin
Png:=TPngImage.Create;
inherited;

end;

destructor TMyAppButton.Destroy;
begin
FreeAndNil(png);
inherited;
end;

procedure TMyAppButton.paint;
var
R:TRect;
begin
R := ClientRect;
Canvas.Brush.Style := bsClear;
if (FInButtonArea = True)then
begin
Png.LoadFromResourceName(HInstance,'app_button');
Canvas.StretchDraw(R,Png);
end;
end;




procedure TMyAppButton.paint;
var
R:TRect;
Png:TPngImage;

begin
Png:=TPngImage.Create;

R := ClientRect;
Canvas.Brush.Style := bsClear;
if (FInButtonArea = True)then
begin
Png.LoadFromResourceName(HInstance,'app_button');
Canvas.StretchDraw(R,Png);
end;
FreeAndNil(png);
end;



请大神指点一下,或者还有其他方法,新手不太会~~~
[解决办法]
当然是第一种,paint会被经常调用的!
[解决办法]
paint方法越少代码越不卡
[解决办法]
第一种,启动的时候加载,尽量避免加载多次。

读书人网 >.NET

热点推荐