winform 中顯示異步下載的圖片
更新時間:2016年05月30日 11:39:15 作者:秦風
本文主要介紹利用WebClient異步下載圖片,顯示在GridView上,需要的朋友可以參考下。
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
////利用 WebClient 來下載圖片
using (WebClient wc = new WebClient())
{
////WebClient 下載完畢的響應事件綁定
wc.DownloadDataCompleted += new DownloadDataCompletedEventHandler(wc_DownloadDataCompleted);
////開始異步下載,圖片URL路徑請根據(jù)實際情況自己去指定
////同時將DataGridView當前行的行號傳遞過去,用于指定圖片顯示的CELL
wc.DownloadDataAsync(new Uri(this.dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString()),
e.RowIndex);
}
}
void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
////如果下載過程未發(fā)生錯誤,并且未被中途取消
if (e.Error == null && !e.Cancelled)
{
////將圖片顯示于對應的指定單元格, 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");
}
}
以上就是顯示異步下載圖片的一些代碼片段,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- WinForm中實現(xiàn)picturebox自適應圖片大小的方法
- C# WinForm控件對透明圖片重疊時出現(xiàn)圖片不透明的簡單解決方法
- WinForm生成驗證碼圖片的方法
- C#實現(xiàn)winform中RichTextBox在指定光標位置插入圖片的方法
- Winform讓DataGridView左側(cè)顯示圖片
- Winform在DataGridView中顯示圖片
- Winform實現(xiàn)將網(wǎng)頁生成圖片的方法
- Winform下實現(xiàn)圖片切換特效的方法
- 基于C# winform實現(xiàn)圖片上傳功能的方法
- Winform 顯示Gif圖片的實例代碼
- winform壁紙工具為圖片添加當前月的日歷信息
- WinForm實現(xiàn)的圖片拖拽與縮放功能示例
相關(guān)文章
C#實現(xiàn)遠程關(guān)閉計算機或重啟計算機的方法
這篇文章主要介紹了C#實現(xiàn)遠程關(guān)閉計算機或重啟計算機的方法,涉及C#遠程連接及系統(tǒng)命令的調(diào)用技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-08-08
C#結(jié)合JavaScript實現(xiàn)手寫板簽名效果
這篇文章主要為大家詳細介紹了C#如何結(jié)合JavaScript實現(xiàn)手寫板寫字并上傳到服務器進行處理,感興趣的小伙伴可以跟隨小編一起學習一下2024-04-04

