Link to home
Start Free TrialLog in
Avatar of ginsonic
ginsonicFlag for Romania

asked on

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 .
ASKER CERTIFIED SOLUTION
Avatar of CalvinDay
CalvinDay

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ginsonic

ASKER

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 ?
Avatar of CalvinDay
CalvinDay

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;
BTW if you want the dragging centered, change the following:

  panel3.Left:=x-panel3.Width div 2;
  panel3.top:=y-panel3.height div 2;