winform 中顯示異步下載的圖片
更新時(shí)間:2016年05月30日 11:39:15 作者:秦風(fēng)
本文主要介紹利用WebClient異步下載圖片,顯示在GridView上,需要的朋友可以參考下。
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
////利用 WebClient 來下載圖片
using (WebClient wc = new WebClient())
{
////WebClient 下載完畢的響應(yīng)事件綁定
wc.DownloadDataCompleted += new DownloadDataCompletedEventHandler(wc_DownloadDataCompleted);
////開始異步下載,圖片URL路徑請(qǐng)根據(jù)實(shí)際情況自己去指定
////同時(shí)將DataGridView當(dāng)前行的行號(hào)傳遞過去,用于指定圖片顯示的CELL
wc.DownloadDataAsync(new Uri(this.dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString()),
e.RowIndex);
}
}
void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
////如果下載過程未發(fā)生錯(cuò)誤,并且未被中途取消
if (e.Error == null && !e.Cancelled)
{
////將圖片顯示于對(duì)應(yīng)的指定單元格, e.UserState 就是傳入的 e.RowIndex
////e.Result 就是下載結(jié)果
this.dataGridView1.Rows[(int)e.UserState].Cells["src"].Value = e.Result;
// this.dataGridView1.Rows[(int)e.UserState].Cells["test"].Value = GetImage("1");
}
}
以上就是顯示異步下載圖片的一些代碼片段,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- WinForm中實(shí)現(xiàn)picturebox自適應(yīng)圖片大小的方法
- C# WinForm控件對(duì)透明圖片重疊時(shí)出現(xiàn)圖片不透明的簡(jiǎn)單解決方法
- WinForm生成驗(yàn)證碼圖片的方法
- C#實(shí)現(xiàn)winform中RichTextBox在指定光標(biāo)位置插入圖片的方法
- Winform讓DataGridView左側(cè)顯示圖片
- Winform在DataGridView中顯示圖片
- Winform實(shí)現(xiàn)將網(wǎng)頁生成圖片的方法
- Winform下實(shí)現(xiàn)圖片切換特效的方法
- 基于C# winform實(shí)現(xiàn)圖片上傳功能的方法
- Winform 顯示Gif圖片的實(shí)例代碼
- winform壁紙工具為圖片添加當(dāng)前月的日歷信息
- WinForm實(shí)現(xiàn)的圖片拖拽與縮放功能示例
相關(guān)文章
C#中使用FilleStream實(shí)現(xiàn)視頻文件的復(fù)制功能
這篇文章主要介紹了C#中使用FilleStream實(shí)現(xiàn)視頻文件的復(fù)制功能,本文通過實(shí)例代碼給大家介紹的非常想詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-09-09
WPF實(shí)現(xiàn)3D翻牌式倒計(jì)時(shí)特效
這篇文章主要為大家詳細(xì)介紹了WPF實(shí)現(xiàn)3D翻牌式倒計(jì)時(shí)特效,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-09-09
C# http系列之以form-data方式上傳多個(gè)文件及鍵值對(duì)集合到遠(yuǎn)程服務(wù)器
這篇文章主要介紹了C# http系列之以form-data方式上傳多個(gè)文件及鍵值對(duì)集合到遠(yuǎn)程服務(wù)器,需要的朋友可以參考下2019-08-08

