动态创建paintbox,为其指定Onpaint事件
我的目的是这样的我是想动态创建一个paintbox,把这些代码都放到formtitle.pas里,然后比如Form1窗体只需要调用这个formtitle.pas里的一个函...
我的目的是这样的
我是想动态创建一个paintbox,把这些代码都放到formtitle.pas里,然后比如Form1窗体只需要调用这个formtitle.pas里的一个函数就能在自己的窗体上创建一个paintbox
1.Form1窗体调用代码:
FormTitle.CreateFormTitle(self,'abc',clWhite,0);
2.formtitle.pas里的全部代码
(其中paint1.OnPaint:=Draws这句代码出错,错误信息为
Incompatible types: 'method pointer and regular procedure'
)
unit FormTitle;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, ComCtrls;
procedure CreateFormTitle(FormName:Tform;TitleCaption:string;TitleColor:TColor;BgColor:integer);
procedure Draws(Sender: TObject);
var
paint1: TPaintBox;
panels:Tpanel;
labels:Tlabel;
implementation
procedure CreateFormTitle(FormName:Tform;TitleCaption:string;TitleColor:TColor;BgColor:integer);
begin
//创建Panel和paintBox
panels:=Tpanel.Create(FormName);
panels.Align:=altop;
panels.SetBounds(0,0,50,40);
panels.Parent:=FormName;
paint1:=TPaintBox.Create(FormName); //uses ExtCtrls
paint1.Parent:=panels;
paint1.Align:=alClient;
paint1.OnPaint:=Draws;
//创建label
labels:=Tlabel.Create(FormName);
with Labels do
begin
Parent:=panels;
Width:=panels.Width;
AutoSize:=true;
Caption:=TitleCaption;
Font.Color:=TitleColor;
Font.Name:='宋体';
Font.Size:=15;
Align:=alClient;
Alignment:=taCenter;
layOut:=tlCenter;
TransParent:=true;
end;
end;
procedure Draws(Sender: TObject);
begin
with paint1.Canvas do
begin
Pen.Color:= clRed;
Rectangle(10, 10, 50, 50);
end;
end;
end. 展开
我是想动态创建一个paintbox,把这些代码都放到formtitle.pas里,然后比如Form1窗体只需要调用这个formtitle.pas里的一个函数就能在自己的窗体上创建一个paintbox
1.Form1窗体调用代码:
FormTitle.CreateFormTitle(self,'abc',clWhite,0);
2.formtitle.pas里的全部代码
(其中paint1.OnPaint:=Draws这句代码出错,错误信息为
Incompatible types: 'method pointer and regular procedure'
)
unit FormTitle;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, ComCtrls;
procedure CreateFormTitle(FormName:Tform;TitleCaption:string;TitleColor:TColor;BgColor:integer);
procedure Draws(Sender: TObject);
var
paint1: TPaintBox;
panels:Tpanel;
labels:Tlabel;
implementation
procedure CreateFormTitle(FormName:Tform;TitleCaption:string;TitleColor:TColor;BgColor:integer);
begin
//创建Panel和paintBox
panels:=Tpanel.Create(FormName);
panels.Align:=altop;
panels.SetBounds(0,0,50,40);
panels.Parent:=FormName;
paint1:=TPaintBox.Create(FormName); //uses ExtCtrls
paint1.Parent:=panels;
paint1.Align:=alClient;
paint1.OnPaint:=Draws;
//创建label
labels:=Tlabel.Create(FormName);
with Labels do
begin
Parent:=panels;
Width:=panels.Width;
AutoSize:=true;
Caption:=TitleCaption;
Font.Color:=TitleColor;
Font.Name:='宋体';
Font.Size:=15;
Align:=alClient;
Alignment:=taCenter;
layOut:=tlCenter;
TransParent:=true;
end;
end;
procedure Draws(Sender: TObject);
begin
with paint1.Canvas do
begin
Pen.Color:= clRed;
Rectangle(10, 10, 50, 50);
end;
end;
end. 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询