继承frame做成一个控件,看例子:
delphi6以后这种组合控件可以直接用继承frame开发,
就和平时的frame一样,都是可视化开发,
只是加一个register过程就成控件了。例子:
单元文件:
unit UShape;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TShapeEdit = class(TFrame)
Edit1: TEdit;
Bevel1: TBevel;
private
{ Private declarations }
public
{ Public declarations }
end;
procedure Register;
implementation
{$R *.dfm}
procedure Register;
begin
RegisterComponents('Sample', [TShapeEdit]);
end;
end.
窗体文件:
object ShapeEdit: TShapeEdit
Left = 0
Top = 0
Width = 104
Height = 48
Anchors = [akLeft, akTop, akRight, akBottom]
TabOrder = 0
DesignSize = (
104
48)
object Bevel1: TBevel
Left = 8
Top = 32
Width = 90
Height = 9
Anchors = [akLeft, akTop, akRight, akBottom]
Shape = bsBottomLine
end
object Edit1: TEdit
Left = 8
Top = 8
Width = 88
Height = 21
Anchors = [akLeft, akTop, akRight, akBottom]
TabOrder = 0
Text = 'Edit1'
end
end
再安装一下就是你要得控件了,注意,窗体文件要一起发布。
可是在窗体中加入这个控件后,在edit的keypress事件中写代码,它在运行时不响应,why?不知大家有没有做过这种组件?
来自:book523, 时间:2003-11-30 13:58:00, ID:2324824 | 编辑
你的问题中的那段话好像我是我说得啊?
好像是我回答一个dfw的问题时的回答啊。
晕!不过没关系,只要把分给我就行了。
你要得到edit1的事件,只要把edit1作为frame的
子控件属性公布出来就行了。真的很好用。
例子:
public
constructor Create(AOwner: TComponent); override;
published
property Edit:TEdit Read edit1 Write Edit1;
implementation
constructor TShapeEdit.Create(AOwner: TComponent);
begin
inherited;
Edit1.SetSubComponent(true); //这句话不能丢,不然不能保存edit1的各种属性。
end;
这样edit1的所有属性,所有事件都有了,
快回去试吧。