procedure TForm1.ButtonMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
r:TRect;
begin
if [ssLeft,ssRight]*Shift=[ssLeft,ssRight]
then exit;
with TControl(Sender)
do
begin
flastpos:=ClientToScreen(Point(x,y));
//um sicherzustellen, daß der Button auf dem Panel bleibt
r:=Parent.ClientRect;
r.TopLeft:=Parent.ClientToScreen(r.TopLeft);
r.BottomRight:=Parent.ClientToScreen(r.BottomRight);
inc(r.Left,x);
dec(r.Right,Width-x);
inc(r.Top,y);
dec(r.Bottom,Height-y);
ClipCursor(@r);
end;
end;
procedure TForm1.ButtonMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
var
mpos:TPoint;
begin
if [ssLeft,ssRight]*Shift=[]
then exit;
with TControl(Sender)
do
begin
mpos:=ClientToScreen(Point(x,y));
x:=mpos.x-flastpos.x;
y:=mpos.y-flastpos.y;
SetBounds(Left+x,Top+y,Width,Height);
flastpos:=mpos;
end;
end;
procedure TForm1.ButtonMouseUp(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
begin
if [ssLeft,ssRight]*Shift<>[]
then exit;
ClipCursor(
nil);
end;