自绘控件时,调用资源图片哪种好一点,该怎么处理
自绘控件时,调用资源图片哪种好一点
请大神指点一下,或者还有其他方法,新手不太会~~~
------解决方案--------------------
当然是第一种,paint会被经常调用的!
------解决方案--------------------
paint方法越少代码越不卡
------解决方案--------------------
第一种,启动的时候加载,尽量避免加载多次。
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方法越少代码越不卡
------解决方案--------------------
第一种,启动的时候加载,尽量避免加载多次。