去看下TCustomLabeledEdit里的这段代码procedure TCustomLabeledEdit.SetLabelPosition(const Value: TLabelPosition); var P: TPoint; begin if FEditLabel = nil then exit; FLabelPosition := Value; case Value of lpAbove: P := Point(Left, Top - FEditLabel.Height - FLabelSpacing); lpBelow: P := Point(Left, Top + Height + FLabelSpacing); lpLeft : P := Point(Left - FEditLabel.Width - FLabelSpacing, Top + ((Height - FEditLabel.Height) div 2)); lpRight: P := Point(Left + Width + FLabelSpacing, Top + ((Height - FEditLabel.Height) div 2)); end; FEditLabel.SetBounds(P.x, P.y, FEditLabel.Width, FEditLabel.Height); end;和 procedure TControl.SetBounds(ALeft, ATop, AWidth, AHeight: Integer); begin if CheckNewSize(AWidth, AHeight) and ((ALeft <> FLeft) or (ATop <> FTop) or (AWidth <> FWidth) or (AHeight <> FHeight)) then begin InvalidateControl(Visible, False); FLeft := ALeft; FTop := ATop; FWidth := AWidth; FHeight := AHeight; UpdateAnchorRules; Invalidate; Perform(WM_WINDOWPOSCHANGED, 0, 0); RequestAlign; if not (csLoading in ComponentState) then Resize; end; end;
var
P: TPoint;
begin
if FEditLabel = nil then exit;
FLabelPosition := Value;
case Value of
lpAbove: P := Point(Left, Top - FEditLabel.Height - FLabelSpacing);
lpBelow: P := Point(Left, Top + Height + FLabelSpacing);
lpLeft : P := Point(Left - FEditLabel.Width - FLabelSpacing,
Top + ((Height - FEditLabel.Height) div 2));
lpRight: P := Point(Left + Width + FLabelSpacing,
Top + ((Height - FEditLabel.Height) div 2));
end;
FEditLabel.SetBounds(P.x, P.y, FEditLabel.Width, FEditLabel.Height);
end;和
procedure TControl.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
if CheckNewSize(AWidth, AHeight) and
((ALeft <> FLeft) or (ATop <> FTop) or
(AWidth <> FWidth) or (AHeight <> FHeight)) then
begin
InvalidateControl(Visible, False);
FLeft := ALeft;
FTop := ATop;
FWidth := AWidth;
FHeight := AHeight;
UpdateAnchorRules;
Invalidate;
Perform(WM_WINDOWPOSCHANGED, 0, 0);
RequestAlign;
if not (csLoading in ComponentState) then Resize;
end;
end;