(看看我的源碼,出了什麼問韙)我想開發一個在treeview中顯示背景圖的控件。(1分)

  • 主题发起人 主题发起人 china_ren
  • 开始时间 开始时间
C

china_ren

Unregistered / Unconfirmed
GUEST, unregistred user!
unit TreeView1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls,extdlgs,Consts;

type
TTreeView1 = class(TTreeView)
private
image:TPicture;
procedure setimage(value:TPicture);
function getcanvas:Tcanvas;
public
constructor create(aowner:tcomponent);override;
destructor destroy;override;
property Canvas:TCanvas read getcanvas;
published
property Picture:TPicture read image write setimage;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [TTreeView1]);
end;

function TTreeView1.GetCanvas: TCanvas;
var
Bitmap: TBitmap;
begin
if image.Graphic = nil then
begin
Bitmap := TBitmap.Create;
try
Bitmap.Width := Width;
Bitmap.Height := Height;
image.Graphic := Bitmap;
finally
Bitmap.Free;
end;
end;
if image.Graphic is TBitmap then
Result := TBitmap(image.Graphic).Canvas;
end;

procedure TTreeView1.setimage(value:TPicture);
begin
ControlStyle := ControlStyle + [csReplicatable];
image.Assign(value);
end;

constructor TTreeView1.create(aowner:tcomponent);
begin
inherited create(aowner);
image:=TPicture.Create;
end;

destructor TTreeView1.destroy;
begin
image.Free;
inherited destroy;
end;

end.
 
后退
顶部