TLabeledEdit是从TCustomEdit继承的,为什么Label可以显示在Edit之外,
我另外加了一个Button,总只能显示在Edit之内,为什么?

解决方案 »

  1.   

    使用了subclass方法,你看看tlabeledit的源码不就知道了?你加button在组件生成的时候要指定button和edit的位置关系的
      

  2.   

    去看下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;