In order to close the form you need to have a link to this form. The easiest way to do so is to add a new property to the Program
object in your program that is static and available everywhere. Just modify your Program.cs
file to make the Program
class public and to add the appropriate reference:
public static class Program
{
///This is your splash screen
public static Form1 MySplashScreen = new Form1();
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
/// This is how you run your main form
Application.Run(MySplashScreen);
}
}
Then in your form you can easily close your splash screen form using the following syntax:
Program.MySplashScreen.Close();
EDIT: In WinForms there is only one GUI thread, so as long as you perform the closing from within another form it should be safe. Should you want to close the form from a working thread spawned from a GUI, use the following code (this should reference your second form then):
this.Invoke((MethodInvoker)delegate {
Program.MySplashScreen.Close();
});