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?
Asked
Active
Viewed 6,898 times
3 Answers
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
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