3

I have two displays (two monitors) connected to my machine, and I noticed a strange thing happening today. I had an Explorer window open with my compiled exe on my primary display, and when I double-clicked it, it opened in the primary display (left monitor). However if I pressed enter to launch the executable, it started in the secondary display (right monitor). The window state of the initial form is maximized. Is there a way to tell C# to open the initial form in the primary display?

slugster
  • 49,403
  • 14
  • 95
  • 145
JeffE
  • 794
  • 2
  • 9
  • 15
  • Thanks for the answers. Does anybody know what causes pressing enter vs double-clicking to result in diff behavior? – JeffE Jan 10 '11 at 22:09

3 Answers3

6

This should do the trick:

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);

    Form1 f = new Form1();
    f.StartPosition = FormStartPosition.Manual;
    f.Location = Screen.PrimaryScreen.Bounds.Location;

    Application.Run(f);
}
SwDevMan81
  • 48,814
  • 22
  • 151
  • 184
1

Take a look at this: Show form on primary or secondary screen

Community
  • 1
  • 1
HABJAN
  • 9,212
  • 3
  • 35
  • 59
0
Screen[] myScreen = Screen.AllScreens;
this.Location = myScreen[0].WorkingArea.Location; // Primary Screen
this.Location = myScreen[1].WorkingArea.Location; // Secondary Screen
Win Phay
  • 1
  • 1
  • 1