scrollbox直接增加casvas功能
如果你要保持一個ScrollBox的VCL物件的話, 可以開一個新的MyCanvas.然後利用MyCanvas.Control指向ScollBox, 那麼你的ScrollBox就擁有Canvas的功能。如果你可以用run time才去Create ScollBox的話, 大可Create一個新的Type繼承ScrollBox, 然後新增一個Property, 而MyCanvas.Control:=Self;即可。type TForm1 = class(TForm) ScrollBox1: TScrollBox; Button1: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure FormDestroy(Sender: TObject); private FMyCanvas: TControlCanvas; procedure SetMyCanvas(const Value: TControlCanvas); { Private declarations } public { Public declarations } property MyCanvas: TControlCanvas read FMyCanvas write SetMyCanvas; // 開一個新的自訂屬性.. end;var Form1: TForm1;implementation{$R *.dfm}{ TForm1 }procedure TForm1.SetMyCanvas(const Value: TControlCanvas);begin FMyCanvas := Value;end;procedure TForm1.FormCreate(Sender: TObject);begin FMyCanvas:=TControlCanvas.Create; FMyCanvas.Control:=ScrollBox1; // 把Canvas與ScrollBox連結;end;// 這一段是試看看有沒有畫出來..procedure TForm1.Button1Click(Sender: TObject);begin MyCanvas.Pen.Color:=clRed; MyCanvas.MoveTo(0,0); MyCanvas.LineTo(100,100);end;?