问题是这样的:
   _______________________
    |                       |
    |   A         B         |
    |                       |
    |    S                  |
    |           V           |
    |                       |
    |   C             H     |
    |                       |
    -------------------------   
    框代表图片(image),字母代表注释(label)
  程序运行时,动态创建多个Timage,和多个Tlabel,每个image对应多个label,
    Tabel 是用来解释Image某个点的说明文字。Tlabel和Timage都的mousedown, mouseMove,mouseup事件。
  它们都可以移动(单个)。现在我想同时多个,其实就是,移动image时,和它对应的label也跟着移动。
  请问:如何实现,给点思路,有源码最好。。谢谢!!

解决方案 »

  1.   

    从写个Label控件就好了  网上载的{
    MSStickyLabel v1.1 July/5/97  by Glenn Shukster & Jacques Scoatarin
        - Released on public.
     V 1.2  Aug/14/97
        - Thanks to Erik B. Berry <[email protected]> &
          Jean-Christophe Boggio <[email protected]> who reported the
          behavior below
        - Corrected weird behavior that occured when the panel was aligned
          bottom and then you assign the TGMSStickylabel
        - Corrected if TGMSStickyLabel is moved from _AttachedTo component
          back to the same _AttachedTo component it would not realign itself.
          Now it does.
        - Corrected when selecting _AttachedTo you could select a component
          who did not have the same parent with poor results:  Added a
          property editor that only displays TWinControls that have the same parent.
     V 1.3 Sep/22/97
        - Thanks to Gerald  [email protected] for reporting the following bug
        - Bug in only Delphi3 version.  When there is something aligned to top and
          a new TGMSStickyLabel is dropped on a component it will loop through all the
          components 3 times with the RectBounds of the TGMSStickyLabel being incorrect
          until the last loop.   In Delphi2 & 1 it only goes thought the loop once with
          the correct co-ordinates.
          Solution was that only attach if (Self.BoundsRect.Top > 0)
          This is a trade off for if you ever try to drop a component at position 0 it will
          not attach.  Drop it just a bit below 0 and it will align no problem.
        - Thanks to Erik B. Berry <[email protected]> for the below improvement
          Eric suggested to have the component alignment be laRightJustify if the _AlignTo
          is alLeft.  This way when editing the caption it will grow away from the control
          its attached to, thus not asking to attach to it again.
     V 1.4 Nov/12/97
        - Added options the following options to the property editor
          alignment (right, left, top, bottom), Set gap, Edit Caption
     V 1.5 Jan/10/98
        - Changed all Assigned(FAttachTo) to the Nil syntax eg. (FAttachTo<>Nil)
          for Delphi 3 in some cases this caused problems
        - Fixed _AttachTo so it could be blanked if needed.  Before once a TWinControl
          was assigned this property could not be empty
        - Added _Offset
        - Thanks to Mike King from London UK at <[email protected]> for suggesting
          this option
     V 2 Jan/27/98
        - Removed the annoying repeated question to attach to another TWinControl when
          you are moving the TWinControl with a TGMSStickylabel attached and it overlaps
          with another TWinControl.
        - Changed name from _Offset to _AlignPosGap, 1.5 was only distributed to a small few,
          thus, now was the time to change it, if you had TGMSStickylabels using _Offset it
          will blank them all to 0.
        - Changed the name of the Component Editor to GMSLabCE.pas (kept it to 8 char for
          Delphi1 compatibility) Delete the old one called LblEdit.pas
        - Added _AlignPos thanks to Erik B. Berry <[email protected]>    DesignIntf,DesignEditors,
    }
    unit XXX;{$D-} { Turns debugger off  comment this line out if you want to step through it}interfaceuses
      Classes,
      StdCtrls,
      Controls,
      Messages,
      Forms,
      Dialogs,
      //DsgnIntf,
      DesignEditors,
      designintf,
    {$IFDEF WIN32}
      SysUtils, { for writing to file for debugging purposes}
      Windows
    {$ELSE}
      WinProcs, WinTypes
    {$ENDIF}
    ;type
      TAlignTo = (alLeft, alTop, alBottom,  alRight);
      TAlignPos = (alTopLeft, alCenter, alBottomRight);
      TGMSStickyLabel = class(TLabel)
      private
        FAttachTo: TWinControl;
        FAlignTo: TAlignTo;
        FAlignPos: TAlignPos;
        FGap : Integer;
        FAlignPosGap:integer;
        FDefAttachedProc: Pointer;
        FAttachedInstance: Pointer;
        FRealigning: Boolean;
        Procedure SetGap(Value: Integer);
        procedure SetAttachTo(Value: TWinControl);
        Procedure SetAlignTo(Value: TAlignTo);
        Procedure SetAlignPosGap(Value: Integer);
        procedure SetAlignPos(Value: TAlignPos);
        { New Attached controls WndProc }
        procedure AttachedWndProc(var Message: TMessage);
        { Procedure ErrFile(sString: String);}
      protected
        procedure CheckForControl;
        procedure Notification(AComponent: TComponent; Operation: TOperation); override;
        procedure SetParent(AParent: TWinControl); override;
        { Override WndProc }
        procedure WndProc(var Message: TMessage); override;
      public
        Procedure _ReAlign;
        constructor Create(AOwner: TComponent); override;
        destructor Destroy; override;
      published
        property _AlignTo: TAlignTo read FAlignTo write SetAlignTo default alLeft;
        property _AttachTo: TWinControl read FAttachTo write SetAttachTo;
        Property _Gap : Integer Read FGap write SetGap Default 5;
        property _AlignPos : TAlignPos Read FAlignPos write SetAlignPos Default alCenter;
        Property _AlignPosGap: integer read FAlignPosGap write SetAlignPosGap default 4;
      end;procedure Register;implementationconstructor TGMSStickyLabel.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      FGap := 5;
      FAlignPosGap := 0;
      FRealigning := False;
      FAlignPos := alCenter;
      { Make Instance out of method }
      FAttachedInstance := MakeObjectInstance(AttachedWndProc);
    end;destructor TGMSStickyLabel.Destroy;
    begin
      { Restore original Attach Control WndProc }
      {   IsWindow check may be uneccessary but doesn't hurt ti be 100% sure }
      if (FAttachTo<>Nil) and IsWindow(FAttachTo.Handle) then
        SetWindowLong(FAttachTo.Handle, GWL_WNDPROC, Longint(FDefAttachedProc));
      { Make method Instance }
      FreeObjectInstance(FAttachedInstance);
      inherited Destroy;
    end;procedure TGMSStickyLabel.AttachedWndProc(var Message: TMessage);
    begin
      with Message do
      begin
        case Msg of
          { On Move/Size message call _ReAlign to keep us aligned! }
          WM_MOVE, WM_SIZE :  _ReAlign;
        end;
        Result := CallWindowProc(FDefAttachedProc, FAttachTo.Handle, Msg, WParam, LParam);
      end;
    end;http://members.tor.shaw.wave.ca/~gms/     //具体下载 地址  太长写不下
      

  2.   

    我Delphi7还在用 很好狠强大
      

  3.   

    1、把你需要组合移动的控件放到同一个窗口里。
    2、在窗口的MouseDown事件里加入代码:
      ReleaseCapture;
      Windows.SendMessage(窗口名.Handle, WM_SYSCOMMAND, $F012, 0);
      

  4.   

    1、把你需要组合移动的控件放到同一个容器里。
    2、在窗口的MouseDown事件里加入代码:  ReleaseCapture;
      Windows.SendMessage(窗口名.Handle, WM_SYSCOMMAND, $F012, 0);
      

  5.   

    简单点的做法,在移动图片的响应时间中,重新设置对应label控件的位置,应该也可以实现,但是实现比较混乱。对应的label位置用图片的相对位置锁定,看看效果如何
      

  6.   

    或者将两个控件放在一个控件上,例如panel,动的时候动panel