1

I have a "borderless" Form with property WindowState = wsMaximized. I can drag the form with this code in the OnMouseDown event of a Panel on the Form:

procedure TForm10.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if button = mbLeft then begin
    ReleaseCapture();
    Self.Perform( WM_SYSCOMMAND, SC_DRAGMOVE, 0 );
  end;
end;

But, after dragging, the Form loses its ability to dock all over the window.

How can I force the Form to dock again, as if it was a bordered Form?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
JimPapas
  • 715
  • 2
  • 12
  • 27
  • I don't understand the purpose of what you are doing. Why would you want to drag a maximized window? – Tom Brunberg Jul 25 '23 at 08:39
  • @TomBrunberg, I want to drag the form to the second monitor and it must be maximized there as was on first monitor. The form must be borderless. – JimPapas Jul 25 '23 at 12:31

1 Answers1

2

Note that, even though you react on the MouseDown event of the panel, you must react to the MouseUp event of the form.

First define the OnMouseUp event for the borderless form. Add code to change the WindowState of the form to wsMaximized. It should look something like this:

procedure TForm9.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  WindowState := wsMaximized;
end;

Then modify your OnMouseDown event to include a call to OnMouseUp() event:

procedure TForm9.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
const
  SC_DRAGMOVE = $F012;
begin
  if Button = mbLeft then begin
    ReleaseCapture;
    Self.Perform(WM_SYSCOMMAND, SC_DRAGMOVE, 0);
    if Assigned(OnMouseUp) then
      FormMouseUp(Sender, Button, Shift, X, Y);
  end;
end;

I have no means to test this in a secondary monitor, but possibly it detects that it is maximized on the second monitor and works as you wish.

Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54
  • If this is the solution then JimPapas **again** forgot an [already existing solution](https://stackoverflow.com/a/76649566/4299358). – AmigoJack Jul 26 '23 at 10:06