Move borderless form in Firemonkey

瘦欲@ 提交于 2019-12-31 05:34:13

问题


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?


回答1:


If the VCL code that you want to replicate is:

SendMessage(MyForm.Handle, WM_SYSCOMMAND, SC_DRAGMOVE, 0);

then the equivalent for FMX would be:

SendMessage(FmxHandleToHWND(MyForm.Handle), WM_SYSCOMMAND, SC_DRAGMOVE, 0);

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 with FmxHandleToHWND().

You may need to declare a couple of constants:

const
  WM_SYSCOMMAND = $0112;
  SC_DRAGMOVE = $F012;



回答2:


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:

procedure TForm4.dragPanelMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
    Self.StartWindowDrag;
end;


来源:https://stackoverflow.com/questions/15381796/move-borderless-form-in-firemonkey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!