C# 在运行时加载图标
我有大约 200 个图标,我想在运行时以树形视图显示它们。 谁能建议我最好的方法来做到这一点。
我是否需要在“app.config”中存储每个图标的“相对路径”并加载? 或者我可以将所有图标编译到 dll 并从那里提取...
或任何其他最适合的想法..?
提前致谢。
I'm having about 200 icons ,which I wanted to display in a treeview on Runtime.
Can anyone suggest me the best way to do this.
Do i need to store "relative path" of each icon in "app.config" and load??
or can I compile all the icons to a dll and extract from there...
or any other best suited idea..?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该将图标添加到项目的资源中,然后它在类 Properties.Resources 中变得可用。
所以你不必存储任何路径。
唯一的缺点是如果你想改变图标,你需要重新编译。
You should add the icons to the resources of your project, and then it becomes available in the class Properties.Resources.
So you dont have to store any paths.
Only drawback is that you need to compile again if you want to change the icons.
最佳选择:在程序集中嵌入资源。
但这确实意味着更改图标将需要重新编译(可以配置使用哪些图标的选择)。
Best option: embedded resources in the assembly.
But it does mean changing the icons will require a recompile (the selection of which icons are used could be configurable).
另一种选择是在设计模式下将图像列表添加到表单中,然后从属性菜单中单击“选择图像”。在此对话框中,您只需选择所有图标,它们就会添加到您的图像列表中。
在您的代码中,您可以通过以下方式访问这些图标
Another option would be to add an ImageList to your Form in Design-Mode and the Click 'Choose images' from the Properties Menu. In this dialog you can simply select all your icons and they will be added to your ImageList.
At your code you can access these icons by