Start Debugging from Visual Studio to Second Monitor
You can't really expect VS to deal with your application's window, so make your gui applications remember the position they had when closed previously. This not only solves the problem you describe perfectly (well, after the very first run), it also makes for a nicer user experience. Look at Get/SetWindowPlacement (can easily be used from C# as well).
I use this code in my debugging application. I set the debug screen as the environment variable DEBUG_SCREEN.
#if DEBUG
if (Debugger.IsAttached)
{
int debugScreen;
if (int.TryParse(Environment.GetEnvironmentVariable("DEBUG_SCREEN") ?? string.Empty, out debugScreen))
{
Application.OpenForms[0].MoveToScreen(debugScreen);
}
}
#endif
You can use your main form instead of Application.OpenForms[0].
The Method MoveToScreen is from Alex Strickland: https://stackoverflow.com/a/34263234/3486660
public static bool MoveToScreen(this System.Windows.Forms.Form form, int screenNumber)
{
var screens = Screen.AllScreens;
if (screenNumber >= 0 && screenNumber < screens.Length)
{
var maximized = false;
if (form.WindowState == FormWindowState.Maximized)
{
form.WindowState = FormWindowState.Normal;
maximized = true;
}
form.Location = screens[screenNumber].WorkingArea.Location;
if (maximized)
{
form.WindowState = FormWindowState.Maximized;
}
return true;
}
return false;
}