In VCL forms I use WM_SYSCOMMAND, but in firemonkey it is undeclared.
I test this code:
procedure TForm4.dragPanelMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
begin
isDraging := true;
X0 := X;
Y0 := Y;
end;
procedure TForm4.dragPanelMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Single);
begin
if isDraging then
begin
Form4.Left := Trunc(Form4.Left + X - X0);
Form4.Top := Trunc(Form4.Top + Y - Y0);
end;
end;
procedure TForm4.dragPanelMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
begin
isDraging := False;
end;
this works, but just for slow moves!!!
How can I move form in Firemonkey?
What easier is just to use the StartWindowDrag method of the Form. This way it will work in both Windows and MacOS and its only 1 line of code. Like so:
If the VCL code that you want to replicate is:
then the equivalent for FMX would be:
The reason is that
MyForm.Handle
is an FMX handle. That's not the same as a window handle. You convert to a window handle withFmxHandleToHWND()
.You may need to declare a couple of constants: