【发布时间】:2019-06-27 16:47:56
【问题描述】:
我创建了一个继承自 Tcustom 控件的简单测试控件,它包含 2 个面板。第一个是与顶部对齐的标题和与 alclient 对齐的客户端面板。
我希望客户端面板接受来自设计器的控件,虽然我可以在面板上放置控件,但它们在运行时不可见,并且在项目关闭时无法正确保存。
控件示例代码如下
unit Testcontrol;
interface
uses Windows,System.SysUtils, System.Classes,System.Types, Vcl.Controls,
Vcl.Forms,Vcl.ExtCtrls,graphics,Messages;
type
TtestControl = class(TCustomControl)
private
FHeader:Tpanel;
FClient:Tpanel;
protected
public
constructor Create(Aowner:Tcomponent);override;
destructor Destroy;override;
published
property Align;
end;
implementation
{ TtestControl }
constructor TtestControl.Create(Aowner: Tcomponent);
begin
inherited;
Fheader:=Tpanel.create(self);
Fheader.Caption:='Header';
Fheader.Height:=20;
Fheader.Parent:=self;
Fheader.Align:=altop;
Fclient:=Tpanel.Create(Self);
with Fclient do
begin
setsubcomponent(true);
ControlStyle := ControlStyle + [csAcceptsControls];
Align:=alclient;
Parent:=self;
color:=clwhite;
BorderStyle:=bssingle;
Ctl3D:=false;
ParentCtl3D:=false;
Bevelouter:=bvnone;
end;
end;
destructor TtestControl.Destroy;
begin
FHeader.Free;
FClient.Free;
inherited;
end;
end.
如果我在测试组件上放置一个按钮,结构会将其显示为表单的一部分,而不是测试组件的子组件......然后它无论如何都不起作用。
有没有办法做到这一点?
【问题讨论】: