Keep new window settings after using MoveWindow
<p>After a long time searching and trying I finally succeeded to move all the screens from the second screen to the primary screen. </p>

<pre><code>[DllImport("user32.dll", SetLastError = true)]
    internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
    [DllImport("user32.dll")]
    public static extern bool GetWindowRect(IntPtr hwnd, ref Rectangle rectangle);

private void putAllWindowsOnPrimairyScreen(){

int procesWidth, procesHeight;

    foreach (Process p in Process.GetProcesses())
    {
       IntPtr id = p.MainWindowHandle;
       Rectangle rect = new Rectangle();
       GetWindowRect(id, ref rect);
       if (!string.IsNullOrEmpty(p.MainWindowTitle))
       {
          if (rect.Height &gt; Screen.PrimaryScreen.Bounds.Height) procesHeight = Screen.PrimaryScreen.Bounds.Height;
          else procesHeight = rect.Height;
          if (rect.Width &gt; Screen.PrimaryScreen.Bounds.Width) procesWidth = Screen.PrimaryScreen.Bounds.Width;
          else procesWidth = rect.Width;
          System.Console.WriteLine(p.MainModule.FileVersionInfo.ProductName);
          MoveWindow(id, 0, 0, procesWidth, procesHeight, true);
        }
    }
}
</code></pre>

<p>However, the screen, in my case Firefox, won't stay at the primairy screen... I can open it once and the second time I try, it restored to the second screen.</p>

<p>How can I make it stay on the primairy screen?</p>

<p>Thanks in advance!</p>
