Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# How to force a slpash screen to be shown in the primary display in a dual-monitor system?

I'm facing a problem when displaying a splash screen in a system with two monitors. When I start the application in the primary display, and then the mouse pointer is moved to the second monitor before the splash screen is shown, my splash screen "follows" the mouse pointer. That means, the splash screen is shown in the 2nd display and after it finishes its work, dissapears and the application is displayed in the primary monitor. This looks pretty ugly and unprofessional.

I have tried to set the property FormStartPosition.CenterScreen in the form's properties and set it in run time in the constructor of my form but none of this has worked. By the way, I'm using C#.

Any hints to achieve that the splash screen be displayed in the same monitor as my application?

Any help will bee deeply appreciated.

Greetings, Victor

like image 600
user452852 Avatar asked Sep 20 '10 15:09

user452852


1 Answers

In Main, you need to force the form to start on the primary monitor. Here's how to open a form at (0, 0) on the primary monitor.

    [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);
    }
like image 103
Alex Morris Avatar answered Sep 20 '22 14:09

Alex Morris