Tpanel のように動作する TCustomControl を作成するにはどうすればよいですか? たとえば、ラベルや画像などのコンポーネントをドロップできる MyCustomComponent などです。
1613 次
1 に答える
8
秘訣は、TCustomPanel の次のコードです。
constructor TCustomPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := [csAcceptsControls {, ... } ];
//...
end;
派生できる VCL コントロールは他にもたくさんありcsAcceptsControls
、それらのControlStyle
プロパティに含まれています。
独自のコントロールでこれを行いたいが、そのような VCL コントロールから派生したものではない場合は、次のようにする必要があります。
- Create コンストラクターをオーバーライドする
- プロパティ
csAcceptsControls
に追加ControlStyle
このサンプル コードのように:
//MMWIN:MEMBERSCOPY
unit _MM_Copy_Buffer_;
interface
type
TMyCustomControl = class(TSomeControl)
public
constructor Create(AOwner: TComponent); override;
end;
implementation
{ TMyCustomControl }
constructor TMyCustomControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle + [csAcceptsControls {, ...} ];
//...
end;
end.
--jeroen
于 2010-07-19T06:54:18.943 に答える