Q
qcchan
Unregistered / Unconfirmed
GUEST, unregistred user!
我想从TPanel继承来生成一个控件,它是一个TPanel加了两个属性,一个是FDyImage :TImage;和FDyLabel :TLabel;,我想对这两个属性赋值后在TPanel能够显示这个图片和标签。下面是我的代码:)不好意思,水平不行,别见笑,DELPHI用了好几年,但从没写过控件,,请高手帮我写一下,万分感谢!!!
unit MyPanel;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls,StdCtrls;
type
TMyPanel = class(TPanel)
private
FPanelCount:Integer;
FDyImage :TImage;
FDyLabel :TLabel;
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy(); override;
published
property PanelCount: Integer read FPanelCount write FPanelCount default 1;
property DyImage: TImage read FDyImage write FDyImage;
property DyLabel: TLabel read FDyLabel write FDyLabel;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TMyPanel]);
end;
constructor TMyPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
//初始化基类值
Width := 75;
Height := 25;
FPanelCount:=10;;//这个是用来测试一下用的
//下面两个是用来创建对象两个用的,我想
//把它们放在Panel上,好象不对
FDyImage:=TImage.Create(AOwner);
FDyImage.Parent:=self ;
FDyImage.Width :=50 ;
FDyImage.Height :=50 ;
FDyImage.Top:=0 ;
FDyImage.Left:=0 ;
FDyLabel :=TLabel.Create(AOwner);
FDyLabel.Parent:=self ;
FDyLabel.Caption :='dfdfd';
FDyLabel.Top:=60 ;
FDyLabel.Left:=0 ;
Repaint;
end;
destructor TMyPanel.Destroy;
begin
inherited;
end;
end
unit MyPanel;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls,StdCtrls;
type
TMyPanel = class(TPanel)
private
FPanelCount:Integer;
FDyImage :TImage;
FDyLabel :TLabel;
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy(); override;
published
property PanelCount: Integer read FPanelCount write FPanelCount default 1;
property DyImage: TImage read FDyImage write FDyImage;
property DyLabel: TLabel read FDyLabel write FDyLabel;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TMyPanel]);
end;
constructor TMyPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
//初始化基类值
Width := 75;
Height := 25;
FPanelCount:=10;;//这个是用来测试一下用的
//下面两个是用来创建对象两个用的,我想
//把它们放在Panel上,好象不对
FDyImage:=TImage.Create(AOwner);
FDyImage.Parent:=self ;
FDyImage.Width :=50 ;
FDyImage.Height :=50 ;
FDyImage.Top:=0 ;
FDyImage.Left:=0 ;
FDyLabel :=TLabel.Create(AOwner);
FDyLabel.Parent:=self ;
FDyLabel.Caption :='dfdfd';
FDyLabel.Top:=60 ;
FDyLabel.Left:=0 ;
Repaint;
end;
destructor TMyPanel.Destroy;
begin
inherited;
end;
end