winform 中显示异步下载的图片
作者:秦风 时间:2022-09-03 19:04:07
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
////利用 WebClient 来下载图片
using (WebClient wc = new WebClient())
{
////WebClient 下载完毕的响应事件绑定
wc.DownloadDataCompleted += new DownloadDataCompletedEventHandler(wc_DownloadDataCompleted);
////开始异步下载,图片URL路径请根据实际情况自己去指定
////同时将DataGridView当前行的行号传递过去,用于指定图片显示的CELL
wc.DownloadDataAsync(new Uri(this.dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString()),
e.RowIndex);
}
}
void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
////如果下载过程未发生错误,并且未被中途取消
if (e.Error == null && !e.Cancelled)
{
////将图片显示于对应的指定单元格, e.UserState 就是传入的 e.RowIndex
////e.Result 就是下载结果
this.dataGridView1.Rows[(int)e.UserState].Cells["src"].Value = e.Result;
// this.dataGridView1.Rows[(int)e.UserState].Cells["test"].Value = GetImage("1");
}
}
标签:winform,图片
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Android列表点击事件定义的一些思考
2021-12-24 08:41:40
![](https://img.aspxhome.com/file/2023/9/137509_0s.jpg)
Android购物分类效果实现
2021-09-20 02:04:10
MyBatis中不建议使用where 1=1原因详解
2021-08-09 23:25:55
![](https://img.aspxhome.com/file/2023/6/79326_0s.jpg)
Android显示网络图片实例
2022-11-02 14:13:31
Android TabHost选项卡标签图标始终不出现的解决方法
2021-08-25 14:32:59
Java基本类型与byte数组之间相互转换方法
2023-11-16 22:49:23
Android MediaPlayer 播放音频的方式
2021-09-07 07:27:09
Android高德地图marker自定义弹框窗口
2023-06-22 13:07:05
![](https://img.aspxhome.com/file/2023/6/114346_0s.jpg)
Java 使用Docker时经常遇到的五个问题
2023-12-10 07:20:21
![](https://img.aspxhome.com/file/2023/7/79317_0s.jpg)
Spring MVC文件配置以及参数传递示例详解
2023-06-03 23:29:48
![](https://img.aspxhome.com/file/2023/0/108460_0s.png)
Java中多线程下载图片并压缩能提高效率吗
2023-08-06 07:40:10
![](https://img.aspxhome.com/file/2023/6/77076_0s.png)
c#中Linq to Sql 增删除的实例
2022-08-24 02:15:34
SpringBoot整合Web之AOP配置详解
2022-01-17 21:38:11
![](https://img.aspxhome.com/file/2023/5/85885_0s.png)
android实现歌词自动滚动效果
2022-03-16 17:09:10
![](https://img.aspxhome.com/file/2023/7/138797_0s.jpg)
布隆过滤器(Bloom Filter)的Java实现方法
2022-09-14 18:06:06
java8的stream如何取max
2023-09-06 19:08:37
![](https://img.aspxhome.com/file/2023/5/96125_0s.png)
Spring+MyBatis实现数据读写分离的实例代码
2021-08-31 04:34:48
Springboot与vue实现数据导出方法具体介绍
2023-11-06 21:00:34
springboot2.5.6集成RabbitMq实现Topic主题模式(推荐)
2021-10-03 22:01:22
![](https://img.aspxhome.com/file/2023/4/83494_0s.png)
Java聊天室之实现接收和发送Socket
2021-06-24 23:30:39
![](https://img.aspxhome.com/file/2023/8/69118_0s.png)