Defining a launcher / form window 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 window with my compiled exe on my main display, and when I double-clicked it, it opened on the main display (left monitor). However, if I pressed the enter button to launch the executable file, it started on the secondary display (right monitor). The state of the initial form window is maximized. Is there any way to tell C # to open the initial form on the main display?

+3
source share
2 answers

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);
}
+5
source
+1

Source: https://habr.com/ru/post/1784610/


All Articles