unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
procedure Button1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
procedure Button1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure Button1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
OldPos: TPoint ;
Pos: TPoint ;
Dragging: Boolean ;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage( '
Clicked' ) ;
end;
procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
if( Button=mbRight )
then
begin
Dragging := True ;
end ;
end;
procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
if( Dragging
and ((X - Pos.X <> OldPos.X)
or (Y - Pos.Y <> OldPos.Y)) )
then
begin
Pos.X := OldPos.X-X ;
Pos.Y := OldPos.Y-Y ;
Button1.Left := Button1.Left - Pos.X ;
Button1.Top := Button1.Top - Pos.Y ;
end ;
OldPos.X := X ;
OldPos.Y := Y ;
end;
procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
Dragging := False ;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Dragging := False ;
end;
end.