获取窗口图标并显示
各位,小弟刚接触VB.Net,有个问题请教一下:在一Windows窗口中有一PictureBox控件,现想在这个PictureBox显示当前窗口的ICO图片标图。该如何做?谢谢!
[解决办法]
PictureBox1.Image = Me.Icon.ToBitmap
[解决办法]
PictureBox的Image属性的类型是System.Drawing.Image。
而窗口图标的类型是System.Drawing.Icon。
这两个类型是不能相互赋值的,也就是说不能这样用:
PictureBox1.Image = Me.Icon
但是System.Drawing.Icon对象有一个叫ToBitmap的方法,可以将System.Drawing.Icon类型转换成System.Drawing.Bitmap类型。由于System.Drawing.Bitmap类型继承于System.Drawing.Image类型,所以可以通过System.Drawing.Icon对象的ToBitmap的方法将图标转换成System.Drawing.Bitmap类型赋值给PictureBox的Image属性。