如果你用的是delphi6,就有现成的控件可用,我试过的,不过我现在用的是5,。
祝:身体健康!

解决方案 »

  1.   

    delphi6不是已经有了吗? 你可以看看它的原代码!
      

  2.   


      要控制它们的位置,我觉得做组合控件方面.现在的C#中的UserControl真的是太方便了。 要不给一段代码给你好了!是一个Lable和Memo组合起来的。unit flyMemo;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TflyLabelMemo = class(TCustomControl)
      private    { Private declarations }
      protected
         procedure Wmsize(Var Message: TMessage) ; message WM_SIZE ;
         procedure CMFontChanged(Var Message :TMessage) ; message CM_FONTCHANGED ;
        { Protected declarations }
      public
          FTitle :TLabel ;
        FTextBox :TMemo ;
        constructor Create (AOwner :TComponent);  override ;
        property Title :TLabel Read FTitle ;
        property TextBox :TMemo Read FTextBox ;
        //这里定义了,则程序能够使用
        { Public declarations }
      published
        //如果这里的定义属性,Object Inspector中就会看到
        { Published declarations }
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('flyLib', [TflyLabelMemo]);   //注册
    end;constructor TflyLabelMemo.Create(Aowner :TComponent) ;
    const
      Gap =5 ;               //label和Memo的间隔
    begin
      inherited Create(Aowner) ;
      Width :=200 ;            //设置新控件的高度
      Height :=120 ;  FTitle :=TLabel.Create(Self) ;
      with FTitle do    //设置label初始的位置(相对新控件),高度
      begin
        Parent :=Self ;
        Caption :='Title' ;
        Left :=Gap ;
        Top :=Gap ;
        Width :=55 ;
        Height :=15 ;
        Visible :=True ;
      end ;  FTextBox :=TMemo.Create(Self) ;
      with FTextBox do    //设置Memo初始的位置(相对新控件),高度
      begin
        Parent :=Self ;
        Left :=FTitle.Left ;
        Top :=FTitle.Top+FTitle.Height+Gap ;
        Width :=Self.Width-Left-Gap ;
        Visible :=True ;
      end ;
    end ;procedure TflyLabelMemo.CMFontChanged(Var Message: TMessage) ;
    begin  //新控件的字体改变了,则需要调整label和Memo的位置
      inherited ;
      FTextBox.Top :=FTitle.Top+FTitle.Height+5 ;
      Height :=FTextBox.Top+FTextBox.Height+5 ;
    end ;procedure TflyLabelMemo.Wmsize(Var Message: TMessage) ;
    begin // //新控件的大小改变了,则需要调整label和Memo的大小
      inherited ;
      FTextBox.Width :=Width-(FTextBox.Left+5) ;
      FTextBox.Height :=Height-(FTextBox.Top+5) ;
    end ;
    end.
      

  3.   

    Delphi6里面已经有现成的了,而且有源代码。
    给你一个LabelEdit的例子,你可以自己扩展他的功能:
    unit CLabelEdit;interfaceuses
      Windows, Messages, SysUtils, Classes, Controls, Graphics, Forms, Dialogs,
      StdCtrls;type
      TCLabelEdit = class(TCustomControl)
      private
        FEdit: TEdit;
        FLabel: TLabel;
        function GetEditText: string;
        function GetLabelText: string;
        procedure SetLabelText(const Value: string);
        procedure SetEditText(const Value: string);
      protected
        procedure WMSize(var Message: TMessage); message WM_SIZE;
        procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
      public
        constructor Create(AOwner: TComponent); override;
      published
        property EditText: string read GetEditText write SetEditText;
        property Font;
        property LabelText: string read GetLabelText write SetLabelText;
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('Samples', [TCLabelEdit]);
    end;{ TCLabelEdit }procedure TCLabelEdit.CMFontChanged(var Message: TMessage);
    begin
      inherited;
      FEdit.Top := FLabel.Top + FLabel.Height + 5;
      Height := FEdit.Top + FEdit.Height + 5;
    end;constructor TCLabelEdit.Create(AOwner: TComponent);
    const
      Gap = 5;
    begin
      inherited Create(AOwner);
      Width := 200;
      Height := 50;
      FLabel := TLabel.Create(Self);
      FLabel.Parent := Self;
      FLabel.Caption := 'Temp';
      FLabel.Left := Gap;
      FLabel.Top := Gap;
      FLabel.Width := 55;
      FLabel.Height := 15;
      FLabel.Visible := True;  FEdit := TEdit.Create(Self);
      FEdit.Parent := Self;
      FEdit.Left := FLabel.Left;
      FEdit.Top := FLabel.Top + FLabel.Height + Gap;
      FEdit.Width := Width - FEdit.Left - Gap;
      FEdit.Visible := True;
    end;function TCLabelEdit.GetEditText: string;
    begin
      Result := FEdit.Text;
    end;function TCLabelEdit.GetLabelText: string;
    begin
      Result := FLabel.Caption;
    end;procedure TCLabelEdit.SetEditText(const Value: string);
    begin
      FEdit.Text := Value;
    end;procedure TCLabelEdit.SetLabelText(const Value: string);
    begin
      FLabel.Caption := Value;
    end;procedure TCLabelEdit.WMSize(var Message: TMessage);
    begin
      inherited;
      FEdit.Width := Width - (FEdit.Left + 5);
    end;end.
      

  4.   

    各位高手,大家好:
    请问一下以下代码有什么错?
    unit MLabel;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TMLabel = class(TLabel)
      private
        { Private declarations }
        Edit:TEdit;
      protected
        { Protected declarations }
      public
        { Public declarations }
        constructor Create (AOwner: TComponent); override;
      published
        { Published declarations }
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('Standard', [TMLabel]);
    end;constructor TMLabel.Create (AOwner: TComponent);
    begin
      inherited Create(Aowner) ;
      Edit:=TEdit.Create(self);
      Edit.Left:=left+width+3;
      edit.Top :=Top;
      Edit.Visible:=false;
      Edit.Visible:=True;
    end;end.
      

  5.   


      难道一定要从类TCustomControl
      继下来吗?
      

  6.   

    constructor TMLabel.Create (AOwner: TComponent);
    begin
      inherited Create(Aowner) ;
      Edit:=TEdit.Create(self);
      Edit.Left:=left+width+3;
      edit.Top :=Top;
    end;
       为什么程序用这个组件时EDIT显示不出来?
      

  7.   

    Edit的Parent属性未赋值,Parent是复杂控件显示的。