Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Main window appears behind other windows after splash screen

Tags:

c#

winforms

I have a Windows Forms Application with a splash screen. When I run the application the splash screen shows up fine, disappears and the main form for the application is loaded.

However, when I load the main form it appears beneath the Windows Explorer directory which contains the application. Here is a segment of code that runs the splash screen and then the main form.

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {        
        public Form1()
        {
            Thread t = new Thread(new ThreadStart(SplashStart));
            t.Start();
            Thread.Sleep(1500);
            InitializeComponent();
            t.Abort();
        }        
        public void SplashStart()
        {
            Application.Run(new SplashScreen());
        }
    }
}   

How can I get Form1 to show above all other windows?

like image 592
DKollar - TruePoint Scanning Avatar asked Jul 07 '15 19:07

DKollar - TruePoint Scanning


2 Answers

Form1.Activate(); 

This should make it the focus and bring to front.

MSDN link: system windows forms form activate

like image 111
Doug E Fresh Avatar answered Nov 03 '22 00:11

Doug E Fresh


Use form.BringToFront() to put the form in front of everything else.

like image 32
Dwedit Avatar answered Nov 03 '22 01:11

Dwedit