阿
阿韬
Unregistered / Unconfirmed
GUEST, unregistred user!
看了TLabeledEdit控件,它一个TLabel和TEdit组合起来的,我想创建一个TCombobox和
TEdit组合起来的控件,不知道该怎么进行下去。我写了代码如下,其中
FBoundLabel.FocusControl := Self这句编译通不过,如果注释掉这句,编译通过,但是
将此控件放到form上的时候看不到Label。
哪位大虾指点一下啊。。。。
TLabelPosition = (lpAbove, lpBelow, lpLeft, lpRight);
TLableCombobox = class(TCombobox)
private
FBoundLabel: TBoundLabel;
FLabelSpacing: Integer;
FShowLabel: Boolean;
FLabelPosition: TLabelPosition;
procedure SetLabelPosition(const Value: TLabelPosition);
procedure SetLabelSpacing(const Value: Integer);
procedure SetShowLabel(Value: Boolean);
protected
public
constructor Create(AOwner: TComponent); override;
property BoundLabel: TBoundLabel read FBoundLabel;
procedure SetBounds(ALeft: Integer; ATop: Integer; AWidth: Integer; AHeight: Integer); override;
procedure SetupInternalLabel;
property LabelSpacing: Integer read FLabelSpacing write SetLabelSpacing;
property LabelPosition: TLabelPosition read FLabelPosition write SetLabelPosition;
published
property ShowLabel: Boolean read FShowLabel write SetShowLabel default True;
end;
//------------------------TLableCombobox---------------------------
procedure TLableCombobox.SetShowLabel(Value: Boolean);
begin
FShowLabel := Value;
FBoundLabel.Visible := FShowLabel;
end;
procedure TLableCombobox.SetLabelSpacing(const Value: Integer);
begin
FLabelSpacing := Value;
SetLabelPosition(FLabelPosition);
end;
procedure TLableCombobox.SetLabelPosition(const Value: TLabelPosition);
var
P: TPoint;
begin
if FBoundLabel = nil then exit;
FLabelPosition := Value;
case Value of
lpAbove: P := Point(Left, Top - FBoundLabel.Height - FLabelSpacing);
lpBelow: P := Point(Left, Top + Height + FLabelSpacing);
lpLeft: P := Point(Left - FBoundLabel.Width - FLabelSpacing,
Top + ((Height - FBoundLabel.Height) div 2));
lpRight: P := Point(Left + Width + FLabelSpacing,
Top + ((Height - FBoundLabel.Height) div 2));
end;
FBoundLabel.SetBounds(P.x, P.y, FBoundLabel.Width, FBoundLabel.Height);
end;
procedure TLableCombobox.SetupInternalLabel;
begin
if Assigned(FBoundLabel) then exit;
FBoundLabel := TBoundLabel.Create(Self);
FBoundLabel.FreeNotification(Self);
FBoundLabel.FocusControl := Self; [red]//此处编译时候报错,提示Undeclared identifier: 'FocusControl '[/red]
end;
procedure TLableCombobox.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
inherited SetBounds(ALeft, ATop, AWidth, AHeight);
SetLabelPosition(FLabelPosition);
end;
constructor TLableCombobox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FShowLabel := True;
FLabelPosition := lpAbove;
FLabelSpacing := 3;
SetupInternalLabel;
end;
TEdit组合起来的控件,不知道该怎么进行下去。我写了代码如下,其中
FBoundLabel.FocusControl := Self这句编译通不过,如果注释掉这句,编译通过,但是
将此控件放到form上的时候看不到Label。
哪位大虾指点一下啊。。。。
TLabelPosition = (lpAbove, lpBelow, lpLeft, lpRight);
TLableCombobox = class(TCombobox)
private
FBoundLabel: TBoundLabel;
FLabelSpacing: Integer;
FShowLabel: Boolean;
FLabelPosition: TLabelPosition;
procedure SetLabelPosition(const Value: TLabelPosition);
procedure SetLabelSpacing(const Value: Integer);
procedure SetShowLabel(Value: Boolean);
protected
public
constructor Create(AOwner: TComponent); override;
property BoundLabel: TBoundLabel read FBoundLabel;
procedure SetBounds(ALeft: Integer; ATop: Integer; AWidth: Integer; AHeight: Integer); override;
procedure SetupInternalLabel;
property LabelSpacing: Integer read FLabelSpacing write SetLabelSpacing;
property LabelPosition: TLabelPosition read FLabelPosition write SetLabelPosition;
published
property ShowLabel: Boolean read FShowLabel write SetShowLabel default True;
end;
//------------------------TLableCombobox---------------------------
procedure TLableCombobox.SetShowLabel(Value: Boolean);
begin
FShowLabel := Value;
FBoundLabel.Visible := FShowLabel;
end;
procedure TLableCombobox.SetLabelSpacing(const Value: Integer);
begin
FLabelSpacing := Value;
SetLabelPosition(FLabelPosition);
end;
procedure TLableCombobox.SetLabelPosition(const Value: TLabelPosition);
var
P: TPoint;
begin
if FBoundLabel = nil then exit;
FLabelPosition := Value;
case Value of
lpAbove: P := Point(Left, Top - FBoundLabel.Height - FLabelSpacing);
lpBelow: P := Point(Left, Top + Height + FLabelSpacing);
lpLeft: P := Point(Left - FBoundLabel.Width - FLabelSpacing,
Top + ((Height - FBoundLabel.Height) div 2));
lpRight: P := Point(Left + Width + FLabelSpacing,
Top + ((Height - FBoundLabel.Height) div 2));
end;
FBoundLabel.SetBounds(P.x, P.y, FBoundLabel.Width, FBoundLabel.Height);
end;
procedure TLableCombobox.SetupInternalLabel;
begin
if Assigned(FBoundLabel) then exit;
FBoundLabel := TBoundLabel.Create(Self);
FBoundLabel.FreeNotification(Self);
FBoundLabel.FocusControl := Self; [red]//此处编译时候报错,提示Undeclared identifier: 'FocusControl '[/red]
end;
procedure TLableCombobox.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
inherited SetBounds(ALeft, ATop, AWidth, AHeight);
SetLabelPosition(FLabelPosition);
end;
constructor TLableCombobox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FShowLabel := True;
FLabelPosition := lpAbove;
FLabelSpacing := 3;
SetupInternalLabel;
end;