unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TMyScrollBox = class(TScrollBox)
public
CC : TCanvas;
public
Buf : TBitmap;
constructor Create(AOwner : TComponent);override;
destructor Destroy;override;
procedure Paint(var Message: TWMPaint); message WM_PAINT;
end;
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
ScrollBox1: TMyScrollBox;
procedure DoPaint;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.DoPaint;
begin
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ScrollBox1 := TMyScrollBox.Create(Self);
ScrollBox1.Parent := Self;
end;
procedure TMyScrollBox.Paint(var Message: TWMPaint);
begin
CC.Handle := GetDC(Handle);
CC.Draw(0,0,Buf);
ReleaseDC(Handle,CC.Handle);
end;
constructor TMyScrollBox.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
CC := TCanvas.Create;
Buf := TBitmap.Create;
Width := 100;
Height := 100;
Buf.Width := Width;
Buf.Height := Height;
end;
destructor TMyScrollBox.Destroy;
begin
CC.Free;
Buf.Free;
inherited;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ScrollBox1.Buf.Canvas.Ellipse(0,0,100,100);
end;
end.
不过我觉得可以有更好的实现方法,可以去看看一些控件的代码。