Ver Mensaje Individual
  #3  
Antiguo 17-06-2008
[coso] coso is offline
Miembro Premium
 
Registrado: may 2008
Ubicación: Girona
Posts: 1.678
Reputación: 0
coso Va por buen camino
Te pongo aqui codigo de ejemplo para hacer un drag&drop

Código Delphi [-]
unit carried;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    Shape1: TShape;
    Shape2: TShape;
    Shape3: TShape;
    Label1: TLabel;
    procedure Shape1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Shape1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Shape1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
    Carried : TControl;
    X_c : integer;
    Y_c : integer;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Shape1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
        if carried <> nil then exit;
        Label1.Caption := inttostr(X_c) + ' ' + inttostr(Y_c);
        Carried := sender as TControl;
        Carried.BringToFront;
        X_c     :=  X;
        Y_c     :=  Y;
end;

procedure TForm1.Shape1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
        m, dh : integer;
begin
        if Carried = nil then exit;

        m := (Width - ClientWidth ) div 2;
        dh := Height - ClientHeight - m;

        Carried.Left := Mouse.CursorPos.x - Left - m - X_c;
        Carried.Top  := Mouse.CursorPos.y - Top - dh - Y_c;
end;

procedure TForm1.Shape1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
        Carried := nil;
end;

end.

Los eventos tienen q estar ligados a todos los shapes.

saludos.

Última edición por coso fecha: 18-06-2008 a las 11:16:12.
Responder Con Cita