为什么我做的控件显示不出来?各位大哥帮帮手!(100分)

  • 主题发起人 主题发起人 HeXiang Lee
  • 开始时间 开始时间
H

HeXiang Lee

Unregistered / Unconfirmed
GUEST, unregistred user!
我做了一个基于TGraphicsControl的控件,成功了,可以使用,
我又做了另外一个也是基于TGraphicsControl,此控件只是把几个前面的控件放到一起.
可是,不见显示!
在此先说声谢谢!
以下是我的源码.是的是做一个像LCD显示的一个时钟.
unit HXLCD;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
NumRang=0..9;
type
tHXLCD = class(TGraphicControl)
private
FNumber: NumRang;
FColor: TColor;
procedure SetColor(const Value: TColor);
procedure SetNumber(const Value: NumRang);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(Owener:TComponent);override;
procedure paint;override;
published
{ Published declarations }
property Color:TColor read FColor write SetColor;
property Number:NumRang read FNumber write SetNumber;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Holy Soft', [tHXLCD]);
end;

{ tHXLCD }

constructor tHXLCD.Create(Owener: TComponent);
begin
inherited Create(Owener);
self.width:=73;
self.Height :=121;
Self.FColor :=clGreen;
Self.FNumber:=0;
end;

procedure tHXLCD.paint;
var
I,K:Integer;
Numbers:array[1..7] of array[1..4] of Integer;
NumberColor:array[1..7] of TColor;
bkColor:Tcolor;
begin
bkColor:=clWhite;
I:=Self.Width div 5;
K:=(Self.Height-I*3) div 2;
Self.Canvas.Brush.Color:=clMenu ;
Self.Canvas.FillRect(Rect(0,0,Self.Width,Self.Height));

Numbers[1,1]:=I;
Numbers[1,2]:=0;
Numbers[1,3]:=Self.Width-I;
Numbers[1,4]:=I;
Numbers[2,1]:=0;
Numbers[2,2]:=I;
Numbers[2,3]:=I;
Numbers[2,4]:=I+K;
Numbers[3,1]:=Self.Width-I;
Numbers[3,2]:=I;
Numbers[3,3]:=Self.width;
Numbers[3,4]:=I+K;
Numbers[4,1]:=I;
Numbers[4,2]:=I+K;
Numbers[4,3]:=Self.Width-I;
Numbers[4,4]:=I*2+K;
Numbers[5,1]:=0;
Numbers[5,2]:=I*2+k;
Numbers[5,3]:=I;
Numbers[5,4]:=Self.Height-I;
Numbers[6,1]:=Self.Width-I;
Numbers[6,2]:=I*2+K;
Numbers[6,3]:=Self.width;
Numbers[6,4]:=Self.Height-I;
Numbers[7,1]:=I;
Numbers[7,2]:=Self.Height-I;
Numbers[7,3]:=Self.Width-I;
Numbers[7,4]:=Self.Height;

case Self.Number of
0: begin
NumberColor[1]:=Self.FColor ;
NumberColor[2]:=Self.FColor ;
NumberColor[3]:=Self.FColor;
NumberColor[4]:=bkColor;
NumberColor[5]:=Self.FColor;
NumberColor[6]:=Self.FColor;
NumberColor[7]:=Self.FColor;
end;
1: begin
NumberColor[1]:=bkColor ;
NumberColor[2]:=bkColor ;
NumberColor[3]:=Self.FColor;
NumberColor[4]:=bkColor;
NumberColor[5]:=bkColor;
NumberColor[6]:=Self.FColor;
NumberColor[7]:=bkColor;
end;
2: begin
NumberColor[1]:=Self.FColor ;
NumberColor[2]:=bkColor ;
NumberColor[3]:=Self.FColor;
NumberColor[4]:=Self.FColor;
NumberColor[5]:=Self.FColor;
NumberColor[6]:=bkColor;
NumberColor[7]:=Self.FColor;;
end;
3: begin
NumberColor[1]:=Self.FColor ;
NumberColor[2]:=bkColor;
NumberColor[3]:=Self.FColor;
NumberColor[4]:=Self.Fcolor;
NumberColor[5]:=bkColor;
NumberColor[6]:=Self.FColor;
NumberColor[7]:=Self.FColor;
end;
4: begin
NumberColor[1]:=bkColor ;
NumberColor[2]:=Self.FColor;
NumberColor[3]:=Self.FColor;
NumberColor[4]:=Self.Fcolor;
NumberColor[5]:=bkColor;
NumberColor[6]:=Self.FColor;
NumberColor[7]:=bkColor;
end;
5: begin
NumberColor[1]:=Self.FColor ;
NumberColor[2]:=Self.FColor;
NumberColor[3]:=bkColor;
NumberColor[4]:=Self.Fcolor;
NumberColor[5]:=bkColor;
NumberColor[6]:=Self.FColor;
NumberColor[7]:=Self.FColor;
end;
6: begin
NumberColor[1]:=Self.FColor ;
NumberColor[2]:=Self.FColor;
NumberColor[3]:=bkColor;
NumberColor[4]:=Self.Fcolor;
NumberColor[5]:=Self.FColor;
NumberColor[6]:=Self.FColor;
NumberColor[7]:=Self.FColor;
end;
7: begin
NumberColor[1]:=Self.FColor ;
NumberColor[2]:=bkColor;
NumberColor[3]:=Self.FColor ;
NumberColor[4]:=bkColor;
NumberColor[5]:=bkColor;
NumberColor[6]:=Self.FColor;
NumberColor[7]:=bkColor;
end;
8: begin
NumberColor[1]:=Self.FColor ;
NumberColor[2]:=Self.FColor ;
NumberColor[3]:=Self.FColor ;
NumberColor[4]:=Self.FColor ;
NumberColor[5]:=Self.FColor ;
NumberColor[6]:=Self.FColor;
NumberColor[7]:=Self.FColor ;
end;
9: begin
NumberColor[1]:=Self.FColor ;
NumberColor[2]:=Self.FColor ;
NumberColor[3]:=Self.FColor ;
NumberColor[4]:=Self.FColor ;
NumberColor[5]:=bkColor;
NumberColor[6]:=Self.FColor;
NumberColor[7]:=Self.FColor ;
end;
end;
for I:=1 to 7 do
begin
Self.Canvas.Brush.Color:=Numbercolor;
Self.Canvas.Rectangle(Numbers[I,1],Numbers[I,2],
Numbers[I,3],Numbers[I,4]);
end;


end;



procedure tHXLCD.SetColor(const Value: TColor);
begin
FColor := Value;
Self.Repaint ;
end;

procedure tHXLCD.SetNumber(const Value: NumRang);
begin
FNumber := Value;
Self.Repaint ;
end;

end.


unit HxTime;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,HxLCD,extctrls;

type
TPoin=Class(TGraphicControl)
private
FColor: Tcolor;
bkColor:Tcolor;
procedure SetColor(const Value: Tcolor);
public
constructor create(Owener:Tcomponent);Override;
procedure paint;override;
published
Property Color:Tcolor read FColor write SetColor;

end;

type
THxTime = class(TGraphicControl)
private
FColor: Tcolor;
Lcd1,Lcd2,Lcd3,Lcd4,Lcd5,Lcd6:ThxLcd;
poin1,poin2:Tpoin;
Timer:TTimer;
bkColor:Tcolor;
procedure SetColor(const Value: Tcolor);
{ Private declarations }

protected
{ Protected declarations }
procedure DoOntimer(Sender:Tobject);
public
{ Public declarations }
constructor create(Owener:Tcomponent);Override;
destructor destory;
procedure paint;override;
published
{ Published declarations }
Property Color:Tcolor read FColor write SetColor;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Holy Soft', [THxTime]);
end;

{ THxTime }

constructor THxTime.create(Owener: Tcomponent);
begin
inherited Create(Owener);
self.bkColor :=clMenu;
self.Lcd1:=thxlcd.Create(self);
self.lcd2:=thxlcd.Create(self);
self.poin1:=tpoin.create(self);
self.poin2:=tpoin.create(self);
self.lcd3:=thxlcd.Create(self);
self.lcd4:=thxlcd.Create(self);
self.lcd5:=thxlcd.Create(self);
self.lcd6:=thxlcd.Create(self);
Timer:=TTimer.Create(self);
Timer.Interval:=1000;
timer.OnTimer :=self.DoOntimer ;
end;

destructor THxTime.destory;
begin
self.Timer.free;
self.Lcd1.free;
self.Lcd2.free;
self.Lcd3.free;
self.Lcd4.free;
self.Lcd5.free;
self.Lcd6.free;
self.poin1.free;
self.poin2.free;
end;

procedure THxTime.DoOntimer(Sender: Tobject);
begin
self.Repaint ;
end;

procedure THxTime.paint;
var
I:Integer;
begin
I:=self.Width div 8;
lcd1.Color:=self.color;
lcd2.color:=self.color;
lcd3.color:=self.color;
lcd4.color:=self.color;
lcd5.color:=self.color;
lcd6.color:=self.color;
poin1.Color :=self.color;
poin2.color:=self.color;

lcd1.Left :=0;
lcd1.Top :=0;
lcd1.Width :=i;
lcd1.Height :=self.Height ;

lcd2.Left :=i+1;
lcd2.Top :=0;
lcd2.Width :=i;
lcd2.Height :=self.Height ;

poin1.Left :=I*2+1;
poin1.Top :=0;
poin1.Width :=i;
poin1.Height :=self.Height ;

lcd3.Left :=i*3+1;
lcd3.Top :=0;
lcd3.Width :=i;
lcd3.Height :=self.Height ;

lcd4.Left :=i*4+1;
lcd4.Top :=0;
lcd4.Width :=i;
lcd4.Height :=self.Height ;

poin2.Left :=I*5+1;
poin2.Top :=0;
poin2.Width :=i;
poin2.Height :=self.Height ;

lcd5.Left :=i*6+1;
lcd5.Top :=0;
lcd5.Width :=i;
lcd5.Height :=self.Height ;

lcd6.Left :=i*7+1;
lcd6.Top :=0;
lcd6.Width :=i;
lcd6.Height :=self.Height ;
lcd1.Repaint ;
end;

procedure THxTime.SetColor(const Value: Tcolor);
begin
FColor := Value;
self.Repaint ;
end;

{ Poin }

constructor TPoin.create(Owener: Tcomponent);
begin
if Not ( owener is thxTime) then
begin
showmessage('Sorry this control is only for the ThxLcd!');
abort;
exit;
end;
self.bkColor:=(Owener as thxtime).bkcolor;
inherited create(owener);
self.Color:=(Owener as thxtime).color;
self.Width :=74;
self.Height:=131;
end;

procedure TPoin.paint;
var
I:integer;
begin
I:=self.Height div 5;
self.Canvas.brush.color:=self.bkColor ;
self.canvas.Rectangle(0,0,self.width,self.height);
self.Canvas.brush.color:=self.color;
self.Canvas.Rectangle(0,I,I,I*2);
self.Canvas.Rectangle(0,i*3,I,I*4);

end;

procedure TPoin.SetColor(const Value: Tcolor);
begin
FColor := Value;
end;

end.
 
哈哈,你可以把TImage放入Panel里,什么时候Image放入Image里过。

GraphicControl继承下来的控件不能包含可显示的子控件

你可以考虑THxTime从 TControl 上继承,并且:
self.Lcd1:=thxlcd.Create(self);
self.Lcd1.Parent := slef;
 
多謝你的相救﹗
不知你有沒有有關控件制作的資料﹐如果有的話能不能發一些給我呢﹖
LHXSZ@21cn.com
 
后退
顶部