title: Open form at cursor position, Delphi
body: <p>I am trying to figure out how to position a Form to open at a given mouse location, despite my monitor settings.</p>
  
  <p>In the Form's <code>OnCreate</code> event, I have this:</p>
  
  <pre><code>procedure TSplashScreen.FormCreate(Sender: TObject);
  Var
     oMousePos: TPoint;
     nLeft, nTop: Integer;
  begin
      Scaled := false;
      PixelsPerInch := Screen.PixelsPerInch;
      Scaled := true;
      //Position:=poScreenCenter;
  
     //center form for 2nd monitor   //zzz
     if (Screen.MonitorCount &gt; 1) then                             //zzz
     begin
        GetCursorPos(oMousePos);
        if (oMousePos.X &gt; Screen.Width) or (oMousePos.X &lt; 0) then
        begin
           Self.Position := poDesigned;
           nLeft := Screen.Monitors[1].Left + Round(Screen.Monitors[1].Width / 2) - Round(Self.Width / 2);
           nTop := Screen.Monitors[1].Top + Round(Screen.Monitors[1].Height / 2) - Round(Self.Height / 2);
           Self.Left := nLeft;
           Self.Top := nTop;
        end;
     end;
  end;
  </code></pre>
  
  <p>When I have 2 monitors, and monitor 1 is set as primary monitor, the Form will open at the mouse cursor.</p>
  
  <p>However, if I set monitor 2 to primary, the Form will always open on monitor 2.</p>