【问题标题】:Cannot convert type 'System.Drawing.Image' to 'System.Drawing.Icon'无法将类型“System.Drawing.Image”转换为“System.Drawing.Icon”
【发布时间】:2019-05-15 22:23:18
【问题描述】:

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

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

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

解决这个问题的最快内存方法是什么?

【问题讨论】:

标签: c# image vb6 vb6-migration converters


【解决方案1】:

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

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

【讨论】:

  • 谢谢@r-j-dunnil
猜你喜欢
  • 2012-02-14
  • 1970-01-01
  • 2012-05-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-03
相关资源
最近更新 更多