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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-04-22 11:00:00 +0000
Seen: 18 times
Last updated: May 26 '22
In Delphi, what is the method for formatting a Unix timestamp?
How can I show a checkmark in a Boolean field in Delphi's DBGrid?
How can memory leaks in UnicodeStrings be addressed in Delphi?
How can POST data be handled in the OnNavigate event when using Delphi TEdgeBrowser?
How can RxLib be used together with Delphi 11?
In Delphi, what is the method to obtain a numeric variant property?
How to display a form or a "please wait" panel while executing a task in FMX Delphi 10.2?