Board index » delphi » Dragging borderless form

Dragging borderless form

  I use the following procedure to drag a borderless form around the
desktop:

private
 procedure WMNCHitTest(var Msg: TWMNCHitTest); message WM_NCHITTEST;
...

procedure TForm1.WMNCHitTest(var Msg: TWMNCHitTest);
begin
     inherited;
     if Msg.Result = htClient then Msg.Result := htCaption;
end;

Is there any way to change the htClient to a TImage?  I tried
'if Msg.Result = Image1 then Msg.Result := htCaption;', but this doesn't
work.  Thanks.

 

Re:Dragging borderless form


Quote
In article <384A1750.2296A...@arrl.net>, John <W...@arrl.net> writes:
>  I use the following procedure to drag a borderless form around the
>desktop:

>private
> procedure WMNCHitTest(var Msg: TWMNCHitTest); message WM_NCHITTEST;
>...

>procedure TForm1.WMNCHitTest(var Msg: TWMNCHitTest);
>begin
>     inherited;
>     if Msg.Result = htClient then Msg.Result := htCaption;
>end;

>Is there any way to change the htClient to a TImage?  I tried
>'if Msg.Result = Image1 then Msg.Result := htCaption;', but this doesn't
>work.  Thanks.

I usually use this in the OnMouseDown of an Item I want to drag like this
(whether it's a form on a screen or a control on it's parent).

const
  SC_DRAGMOVE = $F012;
begin
  ReleaseCapture;
  TWinControl(Sender).Perform(WM_SYSCOMMAND, SC_DRAGMOVE, 0);
end;

You can change the object whose Perform method you call if (for example as you
want to do) you want a mouse down on one control to drag another. ie in your
image's OnMouseDown event handler call the Form1.Perform( method.

Alan Lloyd
alangll...@aol.com

Other Threads