Drag&Drop a panel from a panel to another

I need to drag a panel from another panel toa 3th panel .
Erase the panel from first panel and create it in the second panel .
LVL 9
ginsonicAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CalvinDayCommented:
Place Panel1, Panel2 on a form. Place Panel3 on Panel1. Set Panel3's Dragmode:=dmAutomatic. Here's the code to do the move.


unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    Panel3: TPanel;
    procedure Panel2DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure Panel2DragDrop(Sender, Source: TObject; X, Y: Integer);
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Panel2DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
Accept:=True;
end;

procedure TForm1.Panel2DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
  Panel3.Parent:=Panel2;
end;

end.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ginsonicAuthor Commented:
I wish to simulate the drag&drop .
Your code just splash the panel in another panel . I wish a real drag&drop .
Can help me ?
0
CalvinDayCommented:
Your form and both panels must have this function in the OnDragOver action.

procedure TForm1.FormDragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  Panel3.Parent:=Sender as TWinControl;
  Accept:=True;
  panel3.Left:=x;
  panel3.top:=y;
end;

and the panel3 must have the following  function in the OnDragOver action. This is done so that as the mouse moves over panel3, it will pass its movements to the parent.

procedure TForm1.Panel3DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  FormDragOver(Panel3.Parent, Source, Panel3.Left+X, Panel3.Top+Y, State, Accept);
end;
0
CalvinDayCommented:
BTW if you want the dragging centered, change the following:

  panel3.Left:=x-panel3.Width div 2;
  panel3.top:=y-panel3.height div 2;
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.