1 | initial version |
Yes, the new position of a dynamically shifted control can be saved in Delphi.
You can use the OnMouseUp event of the control to save its new position. For example:
var ControlPosition: TPoint;
procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin ControlPosition := Point(Sender.Left, Sender.Top); end;
procedure TForm1.Button1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin if ssLeft in Shift then begin Sender.Left := Sender.Left + X - ControlPosition.X; Sender.Top := Sender.Top + Y - ControlPosition.Y; end; end;
procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin // save new position to a file or database end;
Note that you will need to implement a way to load the saved position when the form is loaded. This can be done in the FormCreate event, for example.