Author: Jonas Bilinkevicius
How do I get forms been redrawn while moving them? I need a form that snaps
magnetically to another while moved, but there is no event! I've tried the message
WM_WINDOWPOSCHANGING, but it's not possible to show when it fires, because the form
is not redrawn, when moved.
Answer:
Note that MOPSChildForm is the "master" and SearchForm follows it around.
1 2 procedure TMOPSChildForm.WMWindowPosChanging(varmessage: TWMWindowPosChanging);
3 var4 Moving: Boolean;
5 begin6 if SearchForm <> nilthen7 begin8 withmessage.WindowPos^ do9 Moving := (ComponentState * [csReading, csDestroying] = []) and (flags and10 SWP_NOSIZE = 0)
11 and ((x <> Left) or (y <> Top));
12 inherited;
13 if Moving then14 SearchForm.MoveWithForm(HostDockSite <> nil)
15 end;
16 end;
17 18 procedure TMOPSSearch.MoveWithForm(Docked: Boolean);
19 const20 DeltaX = 20; {Offset of this form from MOPSChildForm's TopLeft}21 DeltaY = 40;
22 begin23 if Docked then24 with TForm(TForm(TForm(Owner).HostDockSite).Owner) do25 begin26 Self.Left := Left + DeltaX;
27 Self.Top := Top + DeltaY;
28 end29 else30 with TForm(Owner) do31 begin32 Self.Left := Left + DeltaX;
33 Self.Top := Top + DeltaY;
34 end;
35 end;