1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| using System;
using System.Windows.Forms;
using WebKit;
namespace Protom_Navigator
{
public partial class Form5 : Form
{
private WebKitDownload Download;
private long taille;
private long recv;
public Form5(WebKitDownload Download)
{
this.Download = Download;
InitializeComponent();
this.Visible = false;
Download.DownloadStarted += Download_DownloadStarted;
Download.DownloadReceiveData += Download_DownloadReceiveData;
Download.DownloadFinished += Download_DownloadFinished;
}
//Quand téléchargement finis
private void Download_DownloadFinished(object sender, EventArgs args)
{
progressBar1.Value = progressBar1.Maximum;
label2.Text = "Téléchargement terminé !";
}
//Quand téléchargement est dans le repertoire de téléchargement
private void Download_DownloadReceiveData(object sender, DownloadReceiveDataEventArgs args)
{
recv += args.Length;
label2.Text = recv.ToString() + " / " + taille.ToString() + "B téléchargés";
progressBar1.Value = (int)((((float)recv) / ((float)taille)) * progressBar1.Maximum);
}
//Quand téléchargement commence
private void Download_DownloadStarted(object sender, DownloadStartedEventArgs args)
{
if (MessageBox.Show("Télécharger " + args.SuggestedFileName + "?", "Télécharger", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
taille = args.FileSize;
label1.Text = args.SuggestedFileName;
this.Text = "Téléchargement " + args.SuggestedFileName;
label2.Text = "0";
this.Show();
}
else
{
Download.Cancel();
this.Close();
}
}
//Pour annuler le téléchargement
private void button1_Click(object sender, EventArgs e)
{
Download.Cancel();
this.Close();
}
}
} |
Partager