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. namespace Splash_Screen_With_Progress_Bar
  14. {
  15. public partial class Form1 : Form
  16. {
  17. private FileDownload fd;
  18. public static Splash_Screen splash_s;
  19. private string Link = "http://www.ims.gov.il/Ims/Pages/RadarImage.aspx?Row=9&TotalImages=10&LangID=1&Location=";
  20. private string FileName;
  21. public Form1()
  22. {
  23. InitializeComponent();
  24. splash_s = new Splash_Screen();
  25. fd = new FileDownload(this);
  26. FileName = @"c:\temp\test.jpg";
  27. fd.File_Download(Link, FileName);
  28. splash_s.Show();
  29. for (int i = 1; i < 100; i++)
  30. {
  31. Thread.Sleep(30);
  32. Application.DoEvents();
  33. }
  34. splash_s.SyncedClose();
  35. splash_s = null;
  36. FileDownloadCompleted();
  37. }
  38. public void FileDownloadCompleted()
  39. {
  40. label1.Text = "File Download Completed";
  41. }
  42. private void Form1_Load(object sender, EventArgs e)
  43. {
  44. }
  45. }
  46. }
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. namespace Splash_Screen_With_Progress_Bar
  13. {
  14. public partial class Splash_Screen : Form
  15. {
  16. public Splash_Screen()
  17. {
  18. InitializeComponent();
  19. }
  20. private Mutex mutex = new Mutex();
  21. public void SyncedClose()
  22. {
  23. mutex.WaitOne();
  24. this.Close();
  25. mutex.ReleaseMutex();
  26. }
  27. public void UpdateProgressBar(int percentage)
  28. {
  29. if (this.InvokeRequired)
  30. {
  31. mutex.WaitOne();
  32. if (!IsDisposed)
  33. this.BeginInvoke(new Action<int>(UpdateProgresPRV), percentage);
  34. mutex.ReleaseMutex();
  35. }
  36. else
  37. {
  38. UpdateProgresPRV(percentage);
  39. }
  40. }
  41. private void UpdateProgresPRV(int per)
  42. {
  43. if (progressBar1.IsDisposed) return;
  44. progressBar1.Value = per;
  45. }
  46. private void Splash_Screen_Load(object sender, EventArgs e)
  47. {
  48. }
  49. }
  50. }
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. namespace Splash_Screen_With_Progress_Bar
  9. {
  10. class FileDownload
  11. {
  12. Form1 f1;
  13. public FileDownload(Form1 form1)
  14. {
  15. f1 = form1;
  16. }
  17. HttpWebRequest request;
  18. int currentIndex = 0;
  19. public void File_Download(string uri, string fileName)
  20. {
  21. if (Form1.splash_s != null)
  22. {
  23. if (!Form1.splash_s.IsDisposed)
  24. Form1.splash_s.UpdateProgressBar(0);
  25. }
  26. request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri);
  27. request.CookieContainer = new CookieContainer();
  28. request.AllowAutoRedirect = true;
  29. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  30. long contentLength = response.ContentLength;
  31. if ((response.StatusCode == HttpStatusCode.OK ||
  32. response.StatusCode == HttpStatusCode.Moved ||
  33. response.StatusCode == HttpStatusCode.Redirect) &&
  34. response.ContentType.StartsWith("image", StringComparison.OrdinalIgnoreCase))
  35. {
  36. using (Stream inputStream = response.GetResponseStream())
  37. using (Stream outputStream = File.OpenWrite(fileName))
  38. {
  39. byte[] buffer = new byte[4096];
  40. int bytesRead;
  41. do
  42. {
  43. bytesRead = inputStream.Read(buffer, 0, buffer.Length);
  44. currentIndex += bytesRead;
  45. double percentage = (double)currentIndex / contentLength;
  46. if (Form1.splash_s != null)
  47. {
  48. if (!Form1.splash_s.IsDisposed)
  49. Form1.splash_s.UpdateProgressBar((int)(percentage * 100));
  50. }
  51. outputStream.Write(buffer, 0, bytesRead);
  52. } while (bytesRead != 0);
  53. if (Form1.splash_s != null)
  54. {
  55. if (!Form1.splash_s.IsDisposed)
  56. {
  57. Form1.splash_s.UpdateProgressBar(100);
  58. }
  59. }
  60. }
  61. }
  62. else
  63. {
  64. }
  65. if (Form1.splash_s == null)
  66. f1.FileDownloadCompleted();
  67. }
  68. }
  69. }