gpt4 book ai didi

c# - 如何设置将 ImageList 中的图像转换为图标类型?

转载 作者:行者123 更新时间:2023-11-30 20:08:50 25 4
gpt4 key购买 nike

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

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

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

谢谢。

最佳答案

这里有几个选项。

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

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

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

关于c# - 如何设置将 ImageList 中的图像转换为图标类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6666763/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com