我正在使用VB6将一个VBUC应用程序迁移到C#,但我得到了以下错误:
无法将“System.Drawing.Image”转换为“System.Drawing.Icon”,而我的代码是:
this.Icon = (Icon) ImageList1.Images[0];
this.Text = "Edit Existing Level";记忆中最快的解决方法是哪一种?
发布于 2018-12-14 22:31:22
我编写了一个扩展方法,它将图像转换为位图,然后转换为图标:
public static class MyExtensions
{
public static System.Drawing.Icon ToIcon(this System.Drawing.Image instance)
{
using (System.Drawing.Bitmap bm = (System.Drawing.Bitmap)instance)
{
return System.Drawing.Icon.FromHandle(bm.GetHicon());
}
}
}https://stackoverflow.com/questions/53783253
复制相似问题