unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, ExtCtrls;
type
TForm1 =
class(TForm)
Panel1: TPanel;
SpeedButton1: TSpeedButton;
procedure SpeedButton1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure SpeedButton1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure SpeedButton1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
flastpos:TPoint;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.SpeedButton1MouseDown(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));
// Der Rest ist nur, 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.SpeedButton1MouseMove(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.SpeedButton1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if [ssLeft,ssRight]*Shift<>[]
then exit;
ClipCursor(
nil);
end;
end.