I have a small Windows Forms project and now Iam looking to display an image at project startup, I mean Program.cs
Is it possible?
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Image MyPrgImage = Image.FromFile("C:\\Temp\\Images\\For_Network.gif");
??????
Application.Run(new Form1());
}
Sure… Add new
WindowsFormto your project, call itSplashImageForm. AddPictureBoxcontrol to it, and add the image you want in it. Resize the form, set theseSplashImageFormproperties:Then you want to show that form before Form1 and close it after the timeout has expired… Like so for example:
EDIT
Now, there is new thread which blocks on
System.Threading.Thread.Sleep(2000)for 2 seconds, and the main thread is allowed to block onApplication.Run(f)as it is supposed to, until theSplashImageFormisn’t closed. So the image gets loaded by the main thread and the GUI is responsive.When the timeout ends,
Invoke()method is called so the main thread which is the owner of the form closes it. If this wasn’t here, Cross threaded exception would be thrown.Now the image is shown for 2 secs, and after it Form1 is shown.