各位,如果我制作一个类似与TLabelEdit的组件,我是不是继承一个TEdit,然后在其属性里加上一个TLabel对象?我的问题是怎么定义他们的位置关系?因为不能直接在窗体上移动了,就只能凭空想象位置然后写代码调整Left和Top?是不是做组件在设计期都是不可视的?最好能给个简单的组件例子让我看看,谢了

解决方案 »

  1.   

    重载CreateTMyEdit = class(TEdit)
    private
      FLabel: TLabel;
    public
      constructor Create(AOwner: TComponent); override;
    end;constructor TMyEdit.Create(AOwner: TComponent);
    begin
      inherited;
      FLabel := TLabel.Create(Self);
      FLabel.Parent := Self;
      FLabel.Caption := 'Test';
      FLabel.Top := 0;
      FLabel.Left := 0;
    end;
      

  2.   

    你要的效果应该是这样的~~~TLabelEdit = class(TCustomPanel)
    private
      FLabel: TLabel;
      FEdit: TEdit;
    public
      constructor Create(AOwner: TComponent); override;
    end;constructor TLabelEdit.Create(AOwner: TComponent);
    begin
      inherited;
      Bevelouter := bvNone;
      Self.BorderWidth := 0;
      FLabel := TLabel.Create(Self);
      FLabel.Parent := Self;
      FLabel.Caption := Name;
      FLabel.Top := 3;
      FLabel.Left := 0;
      FEdit := TEdit.Create(Self);
      FEdit.Parent := Self;
      FEdit.Text := Name;
      FEdit.AutoSize := True;
      FEdit.Left := Flabel.Left + FLabel.Width + 5;
      Width := FEdit.Left + FEdit.Width;
      Height := FEdit.Height+2;
    end;