Home > Back-end >  TShape Control the mouse drag and drop question?
TShape Control the mouse drag and drop question?

Time:09-17

I want to when the mouse drag and drop the following code is ShpST1, release the mouse ShpST1 after the current position in the mouse, but when I only within the ShpST1 drag and drop, will run to the position of somehow, when drag and drop on the outside of the ShpST1, can meet the requirements? What reason is this? How to solve?
Drag and drop in the ShpST1 get the position of the X, Y not _click (X, Y?

Procedure TForm1. FormDragOver (Sender, Source: TObject; X, Y: Integer;
State: TDragState; Var Accept: Boolean);
The begin
If (Sender is TShape) then
Accept:=true;
end;


Procedure TForm1. ShpST1DragOver (Sender, Source: TObject; X, Y: Integer;
State: TDragState; Var Accept: Boolean);
The begin

If (Source is TShape) then
Accept:=true;
end;

Procedure TForm1. ShpST1EndDrag (Sender, Target: TObject; X, Y: Integer);
The begin
ShpST1. Brush. Color:=clHighLight;

ShpST1. Left:=X - ShpST1. Width div 2;
ShpST1. Top:=Y - ShpST1. Height div 2;

end;

Procedure TForm1. ShpST1MouseDown (Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
The begin
If the Button=mbLeft then
(Sender as TShape). BeginDrag (false);
end;

CodePudding user response:

Try this code, BCB, can drag for:
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
Void __fastcall TForm1: : Button1MouseDown (TObject * Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
ReleaseCapture ();
The SendMessage (for - & gt; Handle, WM_NCLBUTTONDOWN HTCAPTION, 0);
}
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

CodePudding user response:

Procedure TForm1. ShpST1EndDrag (Sender, Target: TObject; X, Y: Integer);
The begin
ShpST1. Brush. Color:=clHighLight;

ShpST1. Left:=X - ShpST1. Width div 2;
ShpST1. Top:=Y - ShpST1. Height div 2;

end;
In the X and Y are the coordinates of the screen, not the coordinates of the Form

CodePudding user response:

That how to become a Form of X, Y coordinates?
refer to the second floor jinjazz response:
procedure TForm1. ShpST1EndDrag (Sender, Target: TObject; X, Y: Integer);
The begin
ShpST1. Brush. Color:=clHighLight;

ShpST1. Left:=X - ShpST1. Width div 2;
ShpST1. Top:=Y - ShpST1. Height div 2;

end;
In the X and Y are the coordinates of the screen, not the coordinates of the Form

CodePudding user response:

Var
P: TPoint;
The begin
P:=Form1. ScreenToClient (Point (X, Y));
ShpST1. Left:=P.X - ShpST1. Width div 2;
ShpST1. Top:=P.Y - ShpST1. Height div 2;
//...
  • Related