winform 中显示异步下载的图片
2016-05-30 11:39
639 查看
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中实现picturebox自适应图片大小的方法
- C# WinForm控件对透明图片重叠时出现图片不透明的简单解决方法
- WinForm生成验证码图片的方法
- C#实现winform中RichTextBox在指定光标位置插入图片的方法
- Winform让DataGridView左侧显示图片
- Winform在DataGridView中显示图片
- Winform实现将网页生成图片的方法
- Winform下实现图片切换特效的方法
- 基于C# winform实现图片上传功能的方法
- Winform 显示Gif图片的实例代码
- winform壁纸工具为图片添加当前月的日历信息
- WinForm实现的图片拖拽与缩放功能示例
相关文章推荐
- 按右键另存图片只能存BMP
- photoshop去除图片上的水印
- winform绑定快捷键的方法
- 学习Winform文本类控件(Label、Button、TextBox)
- C#实现WinForm捕获最小化事件的方法
- WinForm之BindingSource基础操作实例教程
- upload上传单张图片
- 图片引发的溢出危机(图)
- 在winform下实现左右布局多窗口界面的方法之续篇
- WinForm相对路径的陷阱
- winform实现拖动文件到窗体上的方法
- WinForm实现程序一段时间不运行自动关闭的方法
- C#实现把彩色图片灰度化代码分享
- C#采用Winform实现类似Android的Listener
- WinForm自定义控件应用实例
- WinForm实现为TextBox设置水印文字功能
- C# WinForm 判断程序是否已经在运行,且只允许运行一个实例,附源码
- C#将图片和字节流互相转换并显示到页面上
- C#设置WinForm中DataGrid列的方法(列宽/列标题等)
- winform 实现控制输入法