很巧,我正在做一个项目,也是要用到你说的情况,在panel上作图:本人编写了一个简单的TDrawPanel控件:
源代码如下:
unit DrawPanel;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;
type
TDrawPanel = class(TPanel)
private
fPaint:TNotifyEvent;
{ Private declarations }
protected
procedure Paint;override;
{ Protected declarations }
public
property canvas;
{ Public declarations }
published
property OnPaint:TNotifyEvent read fPaint write fPaint;
{ Published declarations }
end;
procedure Register;
implementation
procedure TDrawPanel.Paint;
begin
inherited;
if Assigned(fPaint) then
fPaint(self);
end;
procedure Register;
begin
RegisterComponents('MyComponent', [TDrawPanel]);
end;
end.
自己把注册就行了,然后就像使用Panel一样使用他,他比panel多了一个Canvas,和OnPaint事件!