This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
UpTool2/UpTool2/DownloadDialog.cs
CreepyCrafter24 cc0201cfb5 Progress Bars
2019-09-10 12:06:15 +02:00

48 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace UpTool2
{
public partial class DownloadDialog : Form
{
WebClient client;
bool close;
public DownloadDialog(string uri, string file)
{
InitializeComponent();
try
{
WebClient client = new WebClient();
client.DownloadProgressChanged += progressChanged;
client.DownloadFileCompleted += done;
client.DownloadFileAsync(new Uri(uri), file);
}
catch
{
DialogResult = DialogResult.Abort;
Close();
}
}
private void done(object sender, AsyncCompletedEventArgs e)
{
DialogResult = DialogResult.OK;
close = true;
Close();
}
private void progressChanged(object sender, DownloadProgressChangedEventArgs e) => progressBar.Value = e.ProgressPercentage;
private void DownloadDialog_FormClosing(object sender, FormClosingEventArgs e) => e.Cancel = !close;
}
}