winform 中顯示異步下載的圖片
更新時間: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路徑請根據(jù)實際情況自己去指定 ////同時將DataGridView當(dāng)前行的行號傳遞過去,用于指定圖片顯示的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) { ////將圖片顯示于對應(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"); } }
以上就是顯示異步下載圖片的一些代碼片段,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- WinForm中實現(xiàn)picturebox自適應(yīng)圖片大小的方法
- 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壁紙工具為圖片添加當(dāng)前月的日歷信息
- WinForm實現(xiàn)的圖片拖拽與縮放功能示例
相關(guān)文章
C#中使用FilleStream實現(xiàn)視頻文件的復(fù)制功能
這篇文章主要介紹了C#中使用FilleStream實現(xiàn)視頻文件的復(fù)制功能,本文通過實例代碼給大家介紹的非常想詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-09-09C# http系列之以form-data方式上傳多個文件及鍵值對集合到遠程服務(wù)器
這篇文章主要介紹了C# http系列之以form-data方式上傳多個文件及鍵值對集合到遠程服務(wù)器,需要的朋友可以參考下2019-08-08