Author: Jonas Bilinkevicius
Is it possible to limit the MDI client form movement, so that the form cannot be
moved outside the client area of the MDI form?
Answer:
Yes, you can handle the WM_WINDOWPOSCHANGING message in the child forms and modify
the message parameters if needs be to keep the child fully visible. Of course this
is a breach of the standard Windows behaviour.
1 private{in form declaration}2 3 procedure WMWINDOWPOSCHANGING(var msg: TWMWINDOWPOSCHANGING);
4 message WM_WINDOWPOSCHANGING;
5 6 procedure TForm1.WMWINDOWPOSCHANGING(var msg: TWMWINDOWPOSCHANGING);
7 var8 r: TRect;
9 begin10 with msg.Windowpos^ do11 begin12 if (flags and SWP_NOMOVE) = 0 then13 begin14 r := GetClientrect(Application.Mainform.handle, r);
15 if x < 0 then16 x := 0;
17 if y < 0 then18 y := 0;
19 if (x + cx) > r.right then20 x := r.right - cx;
21 if (y + cy) > r.bottom then22 y := r.bottom - cy;
23 end;
24 inherited;
25 end;
26 end;