TForm1 =
class(TForm)
Button1: TButton;
procedure Button1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure FormDragDrop(Sender, Source: TObject; X, Y: Integer);
procedure FormDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState;
var Accept: Boolean);
private
{ Private-Deklarationen }
FDragButton : TButton;
public
{ Public-Deklarationen }
end;
procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (Sender
is TButton)
and (Button = mbLeft)
then
begin
FDragButton := TButton (Sender);
FDragButton.BeginDrag (False, 4)
end
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Button1.DragMode := dmManual;
// oder im OI zuweisen
FDragButton :=
nil
end;
procedure TForm1.FormDragDrop(Sender, Source: TObject; X, Y: Integer);
begin
FDragButton :=
nil
end;
procedure TForm1.FormDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState;
var Accept: Boolean);
var
r : TRect;
begin
Accept := Source = FDragButton;
if Accept
then
begin
r := FDragButton.BoundsRect;
if X < r.Left - 1
then
FDragButton.Left := X + 1
else
if r.Right < X
then
FDragButton.Left := X - r.Right + r.Left;
if Y < r.Top - 1
then
FDragButton.Top := Y + 1
else
if r.Bottom < Y
then
FDragButton.Top := Y - r.Bottom + r.Top
end
end;