现编了一个,马上要下班了,没试。
你试试看:
unit scb;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TScb= class(TScrollBox)
private
FCanvas:TCanvas;
function getCanvas:Tcanvas;
procedure setCanvas(c:Tcanvas);
public
constructor Create(AOwner: TComponent);override;
destructor destroy;override;
property Canvas:TCanvas read getCanvas write setCanvas;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [Tscb]);
end;
destructor Tscb.destroy;
begin
fCanvas.Free;
inherited destroy;
end;
constructor Tscb.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
parent:= Twincontrol(AOwner);
fCanvas:=TCanvas.create;
fCanvas.Handle:=getDC(self.Handle);
end;
function Tscb.getCanvas;
begin
if Assigned(fCanvas) then
result:=fCanvas;
end;
procedure Tscb.setCanvas(c:Tcanvas);
begin
if assigned(c) then
begin
fCanvas.Free;
fcanvas:=c;
end
end;
end.