[C#] Gerenciador de Tarefas 13.01.14 0:08
Adicione:
2 Label
2 TextBox
2 Button
1 ProgressBar
1 folderBrowserDialog
Renomeie:
Label 1 >> Direct Link:
Label 2 >> Save File:
Button 1 >> Download
Button 2 >> Save File
De 2 cliques sobre o Form1 em cima de namespace vocês iram adicionar o seguinte codigo:
2 Label
2 TextBox
2 Button
1 ProgressBar
1 folderBrowserDialog
Renomeie:
Label 1 >> Direct Link:
Label 2 >> Save File:
Button 1 >> Download
Button 2 >> Save File
De 2 cliques sobre o Form1 em cima de namespace vocês iram adicionar o seguinte codigo:
- Código:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
Depois de 2 cliques sobre o Button 1 e adicione o seguinte codigo:
- Código:
if (textBox2.Text == String.Empty)//having a if statement to make the program more comfort
{
MessageBox.Show("Please selet a destination to save the file");
}
else
{
WebClient Download_Client = new WebClient();//Declaring the webclient as Download_Client
Download_Client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);//the event handler
Download_Client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);// " "
Download_Client.DownloadFileAsync(new Uri(textBox1.Text.Trim().ToString()), textBox2.Text.Trim());// " "
}
}
Logo abaixo adicione:
- Código:
private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;//setting the progressbar value as downloadprogress
}
private void Completed(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("Downloading Successful ", "Download_Completed", MessageBoxButtons.OK, MessageBoxIcon.Information);//just a messagebox
progressBar1.Value = (0);//resetting the progressbar
textBox1.Text = "";//resetting the textbox
textBox2.Text = "";// " "
}
Agora de 2 cliques sobre o Button 2 e adicione o seguinte codigo:
- Código:
FolderBrowserDialog Save = new FolderBrowserDialog();//Declaring the folder browsing dialog
Save.RootFolder = Environment.SpecialFolder.Desktop;//setting to desktop
if (Save.ShowDialog() == DialogResult.OK)//An if statement to to show the path in textbox
{
textBox2.Text = Save.SelectedPath;
}
string Text = textBox1.Text.ToString();//formatting to string
string[] arry = Text.Split('/');//splitting /
for (int i = 0; i < Int32.Parse(arry.Length.ToString()); i++)//a for loop here
{
if (i == Int32.Parse(arry.Length.ToString()) - 1)
{
textBox2.Text += "\\" + arry[i].ToString();
}
}
}
Créditos:
srDIEGO2014