unit movewin;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
lblmouseX: TLabel;
lblmouseY: TLabel;
lblwidth: TLabel;
lbltop: TLabel;
lblleft: TLabel;
lblheight: TLabel;
lbMouseX: TLabel;
lbMouseY: TLabel;
lbLeft: TLabel;
lbHeight: TLabel;
lbWidth: TLabel;
lbTop: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private-Deklarationen }
DeltaX,DeltaY: Integer;
MouseX,MouseY: Integer;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
lbLeft.Caption := IntToStr(Left);
lbTop.Caption := IntToStr(Top);
lbWidth.Caption := IntToStr(Width);
lbHeight.Caption := IntToStr(Height);
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
LbMouseX.Caption := IntToStr(X);
LbMouseY.Caption := IntToStr(Y);
DeltaX := X - Left;
DeltaY := Y - Top;
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if ssLeft
in Shift
Then
begin
DeltaX := X - Left;
DeltaY := Y - Left;
MouseX := X;
MouseY := Y;
(*
DeltaX := MouseX - Left; // ---- so hatte ich vorher DeltaX
DeltaY := MouseY - Top; // ---- und DeltaY berechnet.
*)
end;
end;
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Left := Left + DeltaX;
Top := Top + DeltaY;
lbLeft.Caption := IntToStr(Left);
lbTop.Caption := IntToStr(Top);
end;
end.