Unit Unit1;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
Type
THitTest = (htMove, htSizeGrip, htNone);
TForm1 =
Class(TForm)
Shape: TShape;
lbInfo: TLabel;
Procedure ShapeMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Procedure ShapeMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
Procedure ShapeMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Procedure FormCreate(Sender: TObject);
private
fDragHitTest: THitTest;
fDragStartX, fDragStartY: Integer;
Function GetHitTest(aPt: TPoint): THitTest;
End;
Var
Form1: TForm1;
Implementation
{$R *.dfm}
Const
ccGap = 4;
// Hot Zone Rahmen
ccHorzGranulation = 21;
ccVertGranulation = 29;
Function TForm1.GetHitTest(aPt: TPoint): THitTest;
Function Between(a, b, c: Integer): Boolean;
// True, wenn a zwischen b und c liegt
Begin
Result := (a >= b)
And (a <= c)
End;
Begin
// untere rechte Ecke (Kann man natürlich besser definieren)
If Between(aPt.X, Width - ccGap + 1, Width)
And Between(aPt.Y, Height - ccGap + 1, Height)
Then
Result := htSizeGrip
// Sonst irgendwo am Rand (geht auch besser)
Else If Between(aPt.X, 0, ccGap)
Or Between(aPt.X, Width - ccGap + 1, Width)
Or Between(aPt.Y, 0, ccGap)
Or Between(aPt.Y, Height - ccGap + 1, Height)
Then
Result := htMove
Else
Result := htNone
End;
Procedure TForm1.ShapeMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y:
Integer);
Begin
fDragHitTest := GetHitTest(Point(X, Y));
fDragStartX := X;
fDragStartY := Y;
End;
Procedure TForm1.ShapeMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
Var
P: TPoint;
Begin
P := ClientToScreen(Point(X, Y));
Case fDragHitTest
Of
htMove:
Begin
Left := P.X - fDragStartX;
Top := P.Y - fDragStartY;
End;
htSizeGrip:
Begin
Width := (1 + X
Div ccVertGranulation) * ccVertGranulation;
// Hier, das meinte ich in
Height := (1 + Y
Div ccHorzGranulation) * ccHorzGranulation;
// meiner Schlaftrunkenheit
End;
End;
End;
Procedure TForm1.ShapeMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
Begin
fDragHitTest := htNone;
End;
Procedure TForm1.FormCreate(Sender: TObject);
Begin
fDragHitTest := htNone;
Shape.Pen.Width := ccGap;
End;
End.