procedure TForm1.ButtonDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
if (Source is TButton) and (TButton(Source).Parent = Panel1) then
Accept := true;
end;
// Source = button dragged
// Sender = button on which Source is dropped
procedure TForm1.ButtonDragDrop(Sender, Source: TObject; X, Y: Integer);
var
pos: Integer;
begin
// Find position of "Sender" in the panel's Z-order.
pos := Panel1.GetControlIndex(TControl(Sender));
// Move "Source" to position of "Sender" in the panel's Z-order.
Panel1.SetControlIndex(TControl(Source), pos);
// Update the childsizing
Panel1.Realign;
end;