Set form position dynamically

Posted in Forms

Use ClientOrigin property of the form. ClientOrigin is the screen coordinates (in pixels) of the top left corner of a control's client area. This property will help you to set your form to the specific position.

uses Unit2;
...
procedure TForm1.Button1Click(Sender: TObject);
var
  NewForm: TForm2;
begin
  NewForm:=TForm2.Create(nil);
  try
    NewForm.Left:=ActiveControl.Width+
                    ActiveControl.Left+
                    ClientOrigin.X;
    NewForm.Top:=ActiveControl.Top+ClientOrigin.Y;
    NewForm.ShowModal;
  finally
    NewForm.Release;
  end;
end;