封装TMyPanel类:
type
TMyPanel = Class(TPanel)
MyLabel: TLabel;
MyComBoBox: TComboBox;
MyBitBtn: TBitBtn;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;implementation{ TMyPanel }constructor TMyPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width:= 500;
Height:= 200;
Left:= 50;
top:= 50;
MyLabel:= TLabel.Create(Self);
MyLabel.Left:= 10;
MyLabel.Top:= 10;
MyLabel.Caption:= 'MyLabel';
MyLabel.Parent:= Self;
MyComBoBox:= TComBoBox.Create(Self);
MyComBoBox.Left:= 100;
MyComBoBox.Top:= 10;
MyComBoBox.Parent:= Self;
MyBitBtn:= TBitBtn.Create(Self);
MyBitBtn.Left:= 160;
MyBitBtn.Top:= 60;
MyBitBtn.caption:='bitbtn1';
MyBitBtn.Parent:= Self;
end;destructor TMyPanel.Destroy;
begin
MyLabel.Free;
MyComBoBox.Free;
MyBitBtn.Free;
inherited Destroy;
end;-------------------------------------------------------------
在form1中调用MyPanel
procedure TForm1.FormCreate(Sender: TObject);
begin
MyPanel:= TMyPanel.Create(self);
MyPanel.Parent:= Self;
end;
如果要省略 MyPanel.Parent:= Self;那么这个类怎么改造?要能正常显示在form1中
解决方案 »
- delphi接口
- 超难问题!!!如何改变 系统任务栏 的 颜色 和字体的颜色 !!!!!!!!!!!! 急!!!!!!!!!!
- 线程的EXECUTE还没结束就执行了类的DESTROY方法,这是怎么回事?
- 哪为高手帮帮忙邮箱的问题 急......
- 本人在計算一文本文件數據時時出現一個浮點數計算錯誤.請指教.
- TreeView插入节点的位置问题,有点难度!
- UpdateSQL 到底有什么用? 哪位高手说两句!!
- 怎么样可以使菜单做成XP风格的
- delphi中提取数据的奇怪问题?
- IdMappedPortTCP1 控件发送问题求助
- windows api初学者应该看什么书?
- SpeedButton.Flat:=true后Glyph为(TBitmap),为什么图片边缘有白色的部分,而不是只显示图片?
constructor TMyPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width:= 500;
Height:= 200;
Left:= 50;
top:= 50;
Parent:= Self; // 加上
...
...
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons;type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; TMyPanel = Class(TPanel)
MyLabel: TLabel;
MyComBoBox: TComboBox;
MyBitBtn: TBitBtn;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;var
Form1: TForm1;implementation{$R *.dfm}constructor TMyPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width:= 500;
Height:= 200;
Left:= 50;
top:= 50;
MyLabel:= TLabel.Create(Self);
MyLabel.Left:= 10;
MyLabel.Top:= 10;
MyLabel.Caption:= 'MyLabel';
MyLabel.Parent:= Self;
MyComBoBox:= TComBoBox.Create(Self);
MyComBoBox.Left:= 100;
MyComBoBox.Top:= 10;
MyComBoBox.Parent:= Self;
MyBitBtn:= TBitBtn.Create(Self);
MyBitBtn.Left:= 160;
MyBitBtn.Top:= 60;
MyBitBtn.caption:='bitbtn1';
MyBitBtn.Parent:= Self;
end;destructor TMyPanel.Destroy;
begin
MyLabel.Free;
MyComBoBox.Free;
MyBitBtn.Free;
inherited Destroy;
end; procedure TForm1.FormCreate(Sender: TObject);
var
MyPanel: TMyPanel;
begin
MyPanel:= TMyPanel.Create(Self);
MyPanel.Parent:= Self;
MyPanel.SetBounds(0, 0, MyPanel.Width, MyPanel.Height);
end;end.
begin
inherited Create(AOwner);
if AOwner is TWinControl then Parent := AOwner as TWinControl;
...
end;
begin
inherited Create(AOwner);
Parent:= TWinControl(FParent);
....