欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

winform 中顯示異步下載的圖片

 更新時(shí)間:2016年05月30日 11:39:15   作者:秦風(fēng)  
本文主要介紹利用WebClient異步下載圖片,顯示在GridView上,需要的朋友可以參考下。
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
  ////利用 WebClient 來(lái)下載圖片
  using (WebClient wc = new WebClient())
  {
    ////WebClient 下載完畢的響應(yīng)事件綁定
    wc.DownloadDataCompleted += new DownloadDataCompletedEventHandler(wc_DownloadDataCompleted);

    ////開(kāi)始異步下載,圖片URL路徑請(qǐng)根據(jù)實(shí)際情況自己去指定
    ////同時(shí)將DataGridView當(dāng)前行的行號(hào)傳遞過(guò)去,用于指定圖片顯示的CELL
    wc.DownloadDataAsync(new Uri(this.dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString()),
      e.RowIndex);
  }
}


void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
  ////如果下載過(guò)程未發(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è)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論