开发者

Specifying startup window/form location on multiple displays

I have two displays (two monitors) connected to my machine, and I noticed a strange thing happening today. I had an Explorer wi开发者_运维百科ndow 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?


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);
}


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


Screen[] myScreen = Screen.AllScreens;
this.Location = myScreen[0].WorkingArea.Location; // Primary Screen
this.Location = myScreen[1].WorkingArea.Location; // Secondary Screen
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜