在Window視窗上放一個Button,一個ProgressBar,一個TextBlock(用來顯示ProgressBar的數值)
利用以下的函式,可以完成
private void Btn_http_Click( object sender, RoutedEventArgs e )
{
// 非同步
WebClient MyWebClient = new WebClient( );
MyWebClient.DownloadFileCompleted += new AsyncCompletedEventHandler( Http_Completed );
MyWebClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler( Http_ProgressChanged );
MyWebClient.DownloadFileAsync( new Uri( "http://www.joyplux.net/xplayer/download/JoyeDM/JoyeDMDownload_Setup.exe" ), @"c:\temp\JoyeDM.exe" );
}
private void Http_ProgressChanged( object sender, DownloadProgressChangedEventArgs e )
{
PgBar_Http.Value = e.ProgressPercentage; //控制ProcessBar顯示進度
TxtBk_Percent.Text = e.ProgressPercentage + "%";
}
private void Http_Completed( object sender, AsyncCompletedEventArgs e )
{
MessageBox.Show( "Download completed!" );
}
沒有留言:
張貼留言