关于复合控件制做,高手指点一下! ( 积分: 50 )

  • 主题发起人 主题发起人 jxsbb
  • 开始时间 开始时间
J

jxsbb

Unregistered / Unconfirmed
GUEST, unregistred user!
我想做一个控件,继承自TWinControl,做一个复合控件,就是panel上有一个speedbutton,但却无法显示出来,请高手看一下问题在哪儿?
谢谢了!

源码:

unit WWinControl1;

interface

uses
SysUtils, Classes, Controls, ExtCtrls, Buttons, Graphics;

type
TWWinControl1 = class(TWinControl)
private
{ Private declarations }
F1:TPanel;
F2:TSpeedButton;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
published
{ Published declarations }
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [TWWinControl1]);
end;

{ TWWinControl1 }

constructor TWWinControl1.Create(AOwner: TComponent);
begin
inherited;
F1:=TPanel.Create(nil);
F1.Parent:=self;
F1.Align:=alLeft;
F1.Width:=self.Width div 2;
F1.Color:=clRed;
F1.Visible:=true;
F2:=TSpeedButton.Create(nil);
F2.Parent:=F1;
F2.Height:=28;
F2.Width:=28;
F2.Top:=0;
F2.Left:=10;
end;

destructor TWWinControl1.Destroy;
begin
F1.Free;
inherited;
end;

end.
 
大小为0当然看不见了

constructor TWWinControl1.Create(AOwner: TComponent);
begin
inherited;
Width := 100;
Height := 50;
F1:=TPanel.Create(nil);
F1.Parent:=self;
F1.Align:=alLeft;
F1.Width:=self.Width div 2;
F1.Color:=clRed;
F1.Visible:=true;
F2:=TSpeedButton.Create(nil);
F2.Parent:=F1;
F2.Height:=28;
F2.Width:=28;
F2.Top:=0;
F2.Left:=10;
end;

另:F2好象没Free噢
个人认为不如直接从TPanel继承,再加个TSpeedButton就行了
 

Similar threads

后退
顶部