Moving a form without a border style

How do I move a borderless form? I tried to look on the Internet, but nothing. Many thanks.

+8
windows forms delphi borderless
source share
2 answers

You can drag and drop a form using any contained control, including yourself.

Using the following example, you can move a form by clicking on its canvas and dragging it. You can do the same with the form panel by placing the same code in the MouseDown panel event, which allows you to create your own pseudo-header panel.

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); const SC_DRAGMOVE = $F012; begin if Button = mbLeft then begin ReleaseCapture; Perform(WM_SYSCOMMAND, SC_DRAGMOVE, 0); end; end; 
+16
source share

If you want to drag the window with the mouse, you can override the WM_NCHITTEST message WM_NCHITTEST and return HTCAPTION for the drag area. The following will drag the window in the top 30 pixels to ensure:

 type TForm1 = class(TForm) private protected procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST; end; .. procedure TForm1.WMNCHitTest(var Message: TWMNCHitTest); var Pt: TPoint; begin Pt := ScreenToClient(SmallPointToPoint(Message.Pos)); if Pt.Y < 30 then Message.Result := HTCAPTION else inherited; end; 
+13
source share

All Articles