无法将类型“ System.Drawing.Image”转换为“ System.Drawing.Icon”

时间:2018-12-14 16:09:52

标签: c# image vb6 vb6-migration converters

我正在使用VBUC将VB6应用程序迁移到C#,但出现此错误:

无法将类型“ System.Drawing.Image”转换为“ System.Drawing.Icon” 而我的代码是:

    this.Icon = (Icon) ImageList1.Images[0];
    this.Text = "Edit Existing Level";

哪种内存解决方案最快?

1 个答案:

答案 0 :(得分:2)

我写了一个扩展方法,将图像转换为位图,然后转换为图标:

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());
        }
    }
}