我准备写一个edit,在他的create事件中我是这样写的:
hintLabel : TLabel;
...
constructor TLabelEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
hintLabel := TLabel.Create(Self);
fCaption := 'Hint:';
hintLabel.Caption := fCaption;
hintLabel.AutoSize := True ;
hintLabel.Visible := True ;
hintLabel.Left := ? //how to write?
hintLabel.Top := ? //how to write?
...
end;可是我看不到hintlabel阿,怎么回事啊?
我想要hintlabel就在我写的这个edit的左边,该怎么写啊?*解答一经调试通过,立即给分!!!
hintLabel : TLabel;
...
constructor TLabelEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
hintLabel := TLabel.Create(Self);
fCaption := 'Hint:';
hintLabel.Caption := fCaption;
hintLabel.AutoSize := True ;
hintLabel.Visible := True ;
hintLabel.Left := ? //how to write?
hintLabel.Top := ? //how to write?
...
end;可是我看不到hintlabel阿,怎么回事啊?
我想要hintlabel就在我写的这个edit的左边,该怎么写啊?*解答一经调试通过,立即给分!!!
是鼠标点在edit的左边就出来,还是一直出现?
你可以把edit的左边重画,专门留一个rect给hintlabel,这样对一个窗口控制好点,2,你可以把label和edit 放成平等的,也就是你的构件父类要改变成
tcomponent,然后进行属性的显示!·
可以参考
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type TExEdit = class(TComponent)
Edits:TEdit;
Hints:TLabel;
private
FParent:TWinControl;
FCaption:String;
FText:string;
FLeft:integer;
FTop:integer;
FVisable:boolean;
public
constructor Create(AOwner: TComponent);
function GetCaption:string;
function GetText:string;
function GetLeft:integer;
function GetTop:integer;
function GetParent:TWinControl;
function GetVisible:boolean; procedure SetCaption(const value:string);
procedure SetText(const value:string);
procedure SetLeft(const value:integer);
procedure SetTop(const value:integer);
procedure SetParent(const value:TWinControl);
procedure SetVisible(const value:boolean); property Parent:TWinControl read GetParent write SetParent;
published
property Caption:string read GetCaption write SetCaption;
property Text:string read GetText write SetText;
property Left:integer read GetLeft write SetLeft;
property Top:integer read GetTop write SetTop;
property Visible:boolean read GetVisible write SetVisible;
end; TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
ExEdit1:TExEdit;
implementation{$R *.dfm}constructor TExEdit.Create(AOwner: TComponent);
begin
inherited;
Edits:=TEdit.Create(self);
Hints:=Tlabel.Create(self);
hints.AutoSize:=true;
end;function TExEdit.GetCaption;
begin
result:=self.Hints.Caption;
end;function TExEdit.GetText;
begin
result:=self.Edits.Text;
end;function TExEdit.GetLeft;
begin
result:=self.Hints.Left;
end;function TExEdit.GetTop;
begin
result:=self.Hints.top;
end;function TExEdit.GetParent;
begin
result:=self.Edits.Parent;
end;function TExEdit.GetVisible;
begin
result:=self.Edits.Visible;
end;procedure TExEdit.SetCaption(const value:string);
begin
self.Hints.Caption:=value;
end;procedure TExEdit.SetText(const value:string);
begin
self.Edits.Text:=value;
end;procedure TExEdit.SetLeft(const value:integer);
begin
self.Hints.Left:=value;
self.Edits.Left:=self.Hints.Left+self.Hints.Width+2;
end;procedure TExEdit.SetTop(const value:integer);
begin
self.Hints.top:=value;
self.Edits.Top:=value;
end;procedure TExEdit.SetParent(const value:TWinControl);
begin
self.Edits.Parent:=value;
self.Hints.Parent:=value;
end;procedure TExEdit.SetVisible(const value:boolean);
begin
self.Edits.Visible:=value;
self.Hints.Visible:=value;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
ExEdit1:=TExEdit.Create(self);
ExEdit1.Parent:=form1;
ExEdit1.Visible:=true;
ExEdit1.Text:='edit';
ExEdit1.Caption:='caption';
ExEdit1.Top:=100;
ExEdit1.Left:=100;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
ExEdit1.Visible:=not ExEdit1.Visible;
end;end.