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

1

13

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

Nuriel answered 20/9, 2010 at 15:18 Comment(2)
A splash screen 'following' the mouse pointer is very unusual. This does not happen by accident, there's surely some code you can comment out to disable this feature. Can't help you find that code of course.Ossified
@HansPassant: This "behavior" afflicts my Winforms application even under .NET 4.0. I am displaying a logon dialog at startup, and it obstinately insists on appearing on whichever monitor happens to "own" the mouse at the moment. It's highly annoying. More interesting, the fix in this post didn't work for me.Ibbison
C
7

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);
    }
Castano answered 20/9, 2010 at 15:34 Comment(2)
Hi Alex, thanks for your answer, unfortunately this didn't help to solve the issue. I should've mentioned that the splash screen is included in a dll (a component created in C#) which is called by a C++ application. So the splash screen has to be shown in the display where the C++ application is started. I tried including the line f.Location = Screen.PrimaryScreen.Bounds.Location; in the constructor of the slpash screen but it didn not help. Any ideas?Nuriel
Hi, the problem was solved including the follwing lines in my Form constructor: this.Location=Screen.PrimaryScreen.Bounds.Location; this.CenterToScreen; If I use this.StartPosition=FormStartPosition.CenterScreen; then I get the described problem. Thanks for the help !Nuriel

© 2022 - 2024 — McMap. All rights reserved.