如何设置将ImageList中的图像转换为图标类型? [英] How set convert Images inside an ImageList to Icon Type?

查看:122
本文介绍了如何设置将ImageList中的图像转换为图标类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在GUI应用程序的ImageList中有一些图标。我想从此列表中设置通知图标,但问题是它只接受图标实例而不是图像。

I have a few icons inside an ImageList in a GUI application. I want to set the notification icon from this list but the problem is it accepts only Icon instances not Image.

System.Windows.Forms.NotifyIcon trayIcon = ...;
System.Windows.Forms.ImageList notifierImageList = ...;

trayIcon.Icon = notifierImageList.Images[0]; //This fails since no such cast exist

谢谢。

推荐答案

这里有几个选项。


  1. 而不是存储ImageList中的图标,您可以将其存储为资源。然后从资源构造一个Icon对象。

  1. Instead of storing the icon in an ImageList, you can store it as a resource. Then construct an Icon object from the resource.

通过创建句柄将图像转换为图标。这是我在网上找到的。

Convert image to icon by creating a handle. This one I found on the web.

notifyIcon1.Icon = Icon.FromHandle(((Bitmap)imageList1.Images[0]).GetHicon());

这篇关于如何设置将ImageList中的图像转换为图标类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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