How to detect current Left and Top of Form when dragging (in Delphi)?

Asked

Viewed 142 times

0

I need to detect the Left and Top value of the Form (in real time) by dragging and displaying the values in Spinedits (Sedtx and Sedty).

I am using the code below, but without success:

 private
   { Private declarations }
   procedure WMNCHitTest(var M: TWMNCHitTest);

Procedure:

procedure TFrmMain.WMNCHitTest(var M: TWMNCHitTest);
begin
 inherited;
    if M.Result = htCaption then
    //Ao arrastar o Form atualiza os SpinEdits
    SEdtX.Value := FrmMain.Left;
    SEdtY.Value := FrmMain.Top;
end;

What should I change?

  • I tried to put in the Form Mousedown, but it doesn’t work.

1 answer

2


The problem is in the method declaration. It expects a operating system message to fire it. Failed to declare which message he is waiting for, the correct statement would be:

procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;

Updating:

The most appropriate message for this purpose is WM_WINDOWPOSCHANGING, this captures in real time the motion of the screen.

procedure WMPosChanging(var Msg: TWmWindowPosChanging); message WM_WINDOWPOSCHANGING;
  • As I declare this trial in Onmousedown?

  • @lukkicode, you do not need to call this procedure in any event, the operating system itself that will trigger you through messages. Just make the declaration of this method in the form class that you want to do your checking and make the necessary negotiations in the same method.

  • Thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.