首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

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

2013-01-01 
自绘控件时,调用资源图片哪种好一点 private{ Private declarations }Png:TPngImageconstructor TMyAppBu

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


 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方法越少代码越不卡
[解决办法]
第一种,启动的时候加载,尽量避免加载多次。

热点排行