Ask Your Question
4

Can the new position of a dynamically shifted control be saved in Delphi?

asked 2021-04-22 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-05-26 20:00:00 +0000

huitzilopochtli gravatar image

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:

  1. Declare a variable in the form or unit to hold the position of the control:

var ControlPosition: TPoint;

  1. In the OnMouseDown event of the control, record its current position:

procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin ControlPosition := Point(Sender.Left, Sender.Top); end;

  1. In the OnMouseMove event of the control, move it based on the mouse movement:

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;

  1. In the OnMouseUp event of the control, save its new position to a file or database:

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.

edit flag offensive delete link more

Your Answer

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

Add Answer


Question Tools

Stats

Asked: 2021-04-22 11:00:00 +0000

Seen: 12 times

Last updated: May 26 '22