Mirror

Make a form snap to the border of the screen (Views: 711)


Problem/Question/Abstract:

I want my form to snap to the left border of the screen as soon as it gets close (Form1.Left<=30) to it. How can I do that?

Answer:

Use the WM_WindowPosChanging message:

procedure WMWindowPosChanging(var Message: TWMWindowPosChanging);
  message WM_WindowPosChanging;
{ ... }

procedure TForm1.WMWindowPosChanging(var Message: TWMWindowPosChanging);
begin
  inherited;
  with Message.WindowPos^ do
    if x < 30 then
      x := 0;
end;

<< Back to main page