D
davidc
Unregistered / Unconfirmed
GUEST, unregistred user!
我现在想要做一个通过TLabel和TEdit复合控件,其中有一个ShowCaption属性,通过True
或False控制TLabel的Visible属性。
type
TCustomldEdit = class(TCustomControl)
private
FEdit: TEdit;
FLabel: TLabel;
......
FShowCaption: boolean;
procedure SetShowCaption(Value: Boolean);
protected
......
public
.....
published
....
property ShowCaption: Boolean read FShowCaption write SetShowCaption default true;
...........
end;
constructor TCustomldEdit.Create(AOwner: TComponent);
const
Gap = 5;
begin
inherited Create(AOwner);
Width := 131;
Height := 50;
FLabel := TLabel.Create(Self);
FLabel.Parent := Self;
FLabel.Caption := 'MyEdit';
FLabel.Left := Gap;
FLabel.Top := Gap;
FLabel.Width := 55;
FLabelWidth := FLabel.Width;
FLabel.Height := 15;
FEdit := TEdit.Create(Self);
FEdit.Parent := Self;
FEdit.Left := FLabel.Left;
FEdit.Top := FLabel.Top + FLabel.Height + Gap;
FEdit.Width := Width - FEdit.Left - Gap;
FShowCaption := true;
end;
procedure TCustomldEdit.SetShowCaption(Value: Boolean);
var
oShow:boolean;
begin
oShow := FShowCaption;
FShowCaption := Value;
if FShowCaption = oShow then exit
else begin
FLabel.Visible := FShowCaption;
showmessage('Run');
end;
end;
在编程时改变该控件的ShowCaption属性时,能够看到ShowMessage('Run'),但是Label
始终没有隐藏,请各位大虾不吝指教。
或False控制TLabel的Visible属性。
type
TCustomldEdit = class(TCustomControl)
private
FEdit: TEdit;
FLabel: TLabel;
......
FShowCaption: boolean;
procedure SetShowCaption(Value: Boolean);
protected
......
public
.....
published
....
property ShowCaption: Boolean read FShowCaption write SetShowCaption default true;
...........
end;
constructor TCustomldEdit.Create(AOwner: TComponent);
const
Gap = 5;
begin
inherited Create(AOwner);
Width := 131;
Height := 50;
FLabel := TLabel.Create(Self);
FLabel.Parent := Self;
FLabel.Caption := 'MyEdit';
FLabel.Left := Gap;
FLabel.Top := Gap;
FLabel.Width := 55;
FLabelWidth := FLabel.Width;
FLabel.Height := 15;
FEdit := TEdit.Create(Self);
FEdit.Parent := Self;
FEdit.Left := FLabel.Left;
FEdit.Top := FLabel.Top + FLabel.Height + Gap;
FEdit.Width := Width - FEdit.Left - Gap;
FShowCaption := true;
end;
procedure TCustomldEdit.SetShowCaption(Value: Boolean);
var
oShow:boolean;
begin
oShow := FShowCaption;
FShowCaption := Value;
if FShowCaption = oShow then exit
else begin
FLabel.Visible := FShowCaption;
showmessage('Run');
end;
end;
在编程时改变该控件的ShowCaption属性时,能够看到ShowMessage('Run'),但是Label
始终没有隐藏,请各位大虾不吝指教。