How to drag a borderless FMX form on the screen through another object?

南楼画角 提交于 2019-12-13 19:15:46

问题


I am trying to make a form draggable on the screen, i.e. that I could grab it and move it around the screen. Its transparent and has no borders, however an image serves to be the background for other controls. I want to use the image's events to control dragging of the form. How can I do that?

I have found the DragEnter, DragLeave, DragStart methods which have this TDragObject argument, I don't know about.

Can somebody help?


回答1:


Basically you have to do it manually.

Here's some delphi/windows code from a form with a transparent Image (TransImage) on it, no borders etc The events are in the form for the Image so Top & Left refer to TMainScanForm.Top/Left.

This will drag your form around using the image events to detect the clicks and moves

...

// Mouse Drag Control
MouseDown: Boolean;
TopLeft,
MouseStart: TPoint;

...

procedure TMainScanForm.TransImageMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  MouseDown := (Button = mbLeft);
  if MouseDown then
  begin
    MouseStart.X := X;
    MouseStart.Y := Y;
    TopLeft := ClientToScreen(MouseStart);
    TopLeft.X := TopLeft.X - X;
    TopLeft.Y := TopLeft.Y - Y;
    end;
end;

procedure TMainScanForm.TransImageMouseMove( Sender: TObject;
                                  Shift: TShiftState;
                                  X, Y: Integer);
var
  NewPoint: TPoint;
begin
  if MouseDown  then
  begin
    NewPoint.X := X;
    NewPoint.Y := Y;
    NewPoint := ClientToScreen(NewPoint);    // On Screen
    NewPoint.Y := NewPoint.Y - MouseStart.Y; // New Onscreen
    NewPoint.X := NewPoint.X - MouseStart.X;
    Top := NewPoint.Y;
    Left := NewPoint.X;
    Refresh;
  end;
end;

procedure TMainScanForm.TransImageMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  MouseDown := False;
end;


来源:https://stackoverflow.com/questions/19197111/how-to-drag-a-borderless-fmx-form-on-the-screen-through-another-object

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