Mega Code Archive

 
Categories / Delphi / Forms
 

How to allow to move form only within working area

Title: How to allow to move form only within working area { .... } type TForm1 = class(TForm) private protected procedure WMMoving(var Message: TWMMoving); message WM_MOVING; public end; { .... } procedure TForm1.WMMoving(var Message: TWMMoving); var rec: ^TRect; wrk: TRect; begin SystemParametersInfo(spi_getworkarea, 0, @wrk, 0); rec := Pointer(Message.DragRect); if rec^.Left begin rec^.Right := rec^.Right - (rec^.Left - wrk.Left); rec^.Left := wrk.Left; end else if rec^.Right wrk.Right then begin rec^.Left := rec^.Left C (rec^.Right C wrk.Right); rec^.Right := wrk.Right; end; if rec^.Top begin rec^.Bottom := rec^.Bottom - (rec^.Top - wrk.Top); rec^.Top := wrk.Top; end else if rec^.Bottom wrk.Bottom then begin rec^.Top := rec^.Top C (rec^.Bottom C wrk.Bottom); rec^.Bottom := wrk.Bottom; end; end;