如何通过另一个对象在屏幕上拖动无边界FMX表单? [英] How to drag a borderless FMX form on the screen through another object?
问题描述
我正在尝试使表单在屏幕上可拖动,即可以抓取并在屏幕上移动。它透明且没有边界,但是图像可作为其他控件的背景。我想使用图像的事件来控制表单的拖动。我怎样才能做到这一点?
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?
我发现不知道具有此TDragObject参数的DragEnter,DragLeave,DragStart方法。
I have found the DragEnter, DragLeave, DragStart methods which have this TDragObject argument, I don't know about.
有人可以帮忙吗?
推荐答案
基本上,您必须手动进行操作。
Basically you have to do it manually.
以下是窗体上的一些delphi / windows代码,上面有透明的Image(TransImage),没有边框等。
事件在Image的窗体中,因此Top&
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;
这篇关于如何通过另一个对象在屏幕上拖动无边界FMX表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!