显示一个图标在PictureBox [英] Displaying an icon in a picturebox

查看:127
本文介绍了显示一个图标在PictureBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个图片框中显示图标文件。我使用此代码来设置图像。

I am trying to display icon file in a picture box. I'm using this code to set the image.

pictureBox1.Image = new Icon(openFileDialog.FileName, new Size(48, 48)).ToBitmap();



但我发现了这个异常。

But I'm getting this exception.

System.ArgumentOutOfRangeException: Requested range extends past the end of the array.
   at System.Runtime.InteropServices.Marshal.CopyToNative(Object source, Int32 startIndex, IntPtr destination, Int32 length)
   at System.Runtime.InteropServices.Marshal.Copy(Byte[] source, Int32 startIndex, IntPtr destination, Int32 length)
   at System.Drawing.Icon.ToBitmap()

如何为了克服这个问题?

How to overcome this problem?

感谢。

推荐答案

问题解决了

pictureBox1.Image = Bitmap.FromHicon(new Icon(openFileDialog.FileName, new Size(48, 48)).Handle);

这篇关于显示一个图标在PictureBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆