Splash screen with Progress Bar

A zip file for download is attached for this project. 
 
Preview screenshots:
 
 
 
 
 This is the form1 code:
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Threading.Tasks;  
  9. using System.Windows.Forms;  
  10. using System.IO;  
  11. using System.Net;  
  12. using System.Threading;  
  13.   
  14. namespace Splash_Screen_With_Progress_Bar  
  15. {  
  16.   
  17.     public partial class Form1 : Form  
  18.     {  
  19.         private FileDownload fd;  
  20.         public static Splash_Screen splash_s;  
  21.         private string Link = "http://www.ims.gov.il/Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location=";  
  22.         private string FileName;  
  23.   
  24.         public Form1()  
  25.         {  
  26.             InitializeComponent();  
  27.   
  28.             splash_s = new Splash_Screen();  
  29.             fd = new FileDownload(this);  
  30.             FileName = @"c:\temp\test.jpg";  
  31.   
  32.             fd.File_Download(Link, FileName);  
  33.             splash_s.Show();  
  34.               
  35.             for (int i = 1; i < 100; i++)  
  36.             {  
  37.                 Thread.Sleep(30);  
  38.                 Application.DoEvents();  
  39.             }  
  40.             splash_s.SyncedClose();  
  41.             splash_s = null;  
  42.             FileDownloadCompleted();  
  43.         }  
  44.   
  45.         public void FileDownloadCompleted()  
  46.         {  
  47.             label1.Text = "File Download Completed";  
  48.         }  
  49.   
  50.         private void Form1_Load(object sender, EventArgs e)  
  51.         {  
  52.   
  53.         }  
  54.     }  
  55. }  
 This is the code of the Splash screen form:
 
The Splash screen form i called it Splash_Screen_With_Progress_Bar
I added to the Splash form in the designer a background image then set the form size to 589,260 and the properties Start Position = center screen , Show in taskbar = false , Form Border Style = none ,  AutoScale Mod = font
 
Then I added a progressBar control to the form and set it's property Dock to Bottom.

The progressBar size is: 589,23 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Threading.Tasks;  
  9. using System.Windows.Forms;  
  10. using System.Threading;  
  11. using System.IO;  
  12.   
  13. namespace Splash_Screen_With_Progress_Bar  
  14. {  
  15.     public partial class Splash_Screen : Form  
  16.     {  
  17.         public Splash_Screen()  
  18.         {  
  19.             InitializeComponent();  
  20.         }  
  21.   
  22.         private Mutex mutex = new Mutex();  
  23.         public void SyncedClose()  
  24.         {  
  25.             mutex.WaitOne();  
  26.             this.Close();  
  27.             mutex.ReleaseMutex();  
  28.         }  
  29.         public void UpdateProgressBar(int percentage)  
  30.         {  
  31.   
  32.             if (this.InvokeRequired)  
  33.             {  
  34.                 mutex.WaitOne();  
  35.                 if (!IsDisposed)  
  36.                     this.BeginInvoke(new Action<int>(UpdateProgresPRV), percentage);  
  37.                 mutex.ReleaseMutex();  
  38.             }  
  39.             else  
  40.             {  
  41.                 UpdateProgresPRV(percentage);  
  42.             }  
  43.         }  
  44.   
  45.         private void UpdateProgresPRV(int per)  
  46.         {  
  47.             if (progressBar1.IsDisposed) return;  
  48.             progressBar1.Value = per;  
  49.         }  
  50.   
  51.         private void Splash_Screen_Load(object sender, EventArgs e)  
  52.         {  
  53.   
  54.         }  
  55.     }  
  56. }  
 This is the FileDownload class:
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using System.Net;  
  7. using System.IO;  
  8.   
  9. namespace Splash_Screen_With_Progress_Bar  
  10. {  
  11.     class FileDownload  
  12.     {  
  13.   
  14.         Form1 f1;  
  15.   
  16.         public FileDownload(Form1 form1)  
  17.         {  
  18.             f1 = form1;  
  19.         }  
  20.   
  21.         HttpWebRequest request;  
  22.         int currentIndex = 0;  
  23.         public void File_Download(string uri, string fileName)  
  24.         {  
  25.             if (Form1.splash_s != null)  
  26.             {  
  27.                 if (!Form1.splash_s.IsDisposed)  
  28.                     Form1.splash_s.UpdateProgressBar(0);  
  29.             }  
  30.             request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);  
  31.             request.CookieContainer = new CookieContainer();  
  32.             request.AllowAutoRedirect = true;  
  33.   
  34.             HttpWebResponse response = (HttpWebResponse)request.GetResponse();  
  35.             long contentLength = response.ContentLength;  
  36.             if ((response.StatusCode == HttpStatusCode.OK ||  
  37.                 response.StatusCode == HttpStatusCode.Moved ||  
  38.                 response.StatusCode == HttpStatusCode.Redirect) &&  
  39.                 response.ContentType.StartsWith("image", StringComparison.OrdinalIgnoreCase))  
  40.             {  
  41.                 using (Stream inputStream = response.GetResponseStream())  
  42.                 using (Stream outputStream = File.OpenWrite(fileName))  
  43.                 {  
  44.                     byte[] buffer = new byte[4096];  
  45.                     int bytesRead;  
  46.                     do  
  47.                     {  
  48.                         bytesRead = inputStream.Read(buffer, 0, buffer.Length);  
  49.                         currentIndex += bytesRead;  
  50.                         double percentage = (double)currentIndex / contentLength;  
  51.                         if (Form1.splash_s != null)  
  52.                         {  
  53.                             if (!Form1.splash_s.IsDisposed)  
  54.                                 Form1.splash_s.UpdateProgressBar((int)(percentage * 100));  
  55.                         }  
  56.                         outputStream.Write(buffer, 0, bytesRead);  
  57.                     } while (bytesRead != 0);  
  58.                     if (Form1.splash_s != null)  
  59.                     {  
  60.                         if (!Form1.splash_s.IsDisposed)  
  61.                         {  
  62.                             Form1.splash_s.UpdateProgressBar(100);  
  63.                         }  
  64.                     }  
  65.                 }  
  66.   
  67.             }  
  68.             else  
  69.             {  
  70.                  
  71.             }  
  72.             if (Form1.splash_s == null)  
  73.                 f1.FileDownloadCompleted();  
  74.         }  
  75.     }  
  76. }