我想做一个TImage控件,在它的里面是一个可编辑的TEdit(或TPanel),如下图所视,并且单图形移动时,TEdit或TPanel要一起移动,字体要中间对齐,该怎样做。***********************************************
*                                             *
*                                             *
*                                             *
*                                             *
*                                             *
*                                             *
***********************************************
*                 TEdit(或TPanel等)           *
***********************************************

解决方案 »

  1.   

    继承于TControl,在Create函数中创建Image及Edit即可。
      

  2.   

    unit myControl;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, stdctrls ,Dialogs, extctrls;type
      TmyControl = class(TCustomControl)
      private
        FImage: TImage;
        FPicture: TPicture;
        FPanel: TPanel;
        FEdit: TEdit;
      protected
        function GetEditText: String;
        Procedure SetEditText(const Value: String);
        procedure SetPicture(Value: TPicture);
      public
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
      published
        property Picture: TPicture read FPicture write SetPicture;
        property EditText: string read GetEditText write SetEditText;
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('System', [TmyControl]);
    end;{ TmyControl }constructor TmyControl.Create(AOwner: TComponent);
    begin
      inherited;
      //
      Width := 200;
      Height := 200;
      
      FPanel := TPanel.Create(Self);
      FPanel.Parent := Self;
      FPanel.Align := alBottom;
      FPanel.Visible := True;
      
      FPicture := TPicture.Create;  FImage := TImage.Create(Self);
      FImage.Parent := Self;
      FImage.Align := alClient;
      FImage.Visible := True;  FEdit := TEdit.Create(Self);
      FEdit.Parent := Self;
      FEdit.Parent := FPanel;
      FEdit.Visible := True;
    end;destructor TmyControl.Destroy;
    begin
      FPicture.Free;
      inherited;
    end;function TmyControl.GetEditText: String;
    begin
      //
      Result := FEdit.Text;
    end;procedure TmyControl.SetEditText(const Value: string);
    begin
      //
      FEdit.Text := Value;
    end;procedure TmyControl.SetPicture(Value: TPicture);
    begin
      FPicture.Assign(Value);
      FImage.Picture := FPicture;
    end;
    end.