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
  • 48,492
  • 14
  • 96
  • 143
JeffE
  • 764
  • 2
  • 8
  • 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
  • 47,539
  • 21
  • 146
  • 180
1

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

Community
  • 1
  • 1
HABJAN
  • 8,943
  • 3
  • 34
  • 56
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