如何在MenuItem中添加图标 [英] How to an add an icon to a MenuItem

查看:82
本文介绍了如何在MenuItem中添加图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!

我有一个添加了各种项目的ContextMenu.

如何在这些项目上添加图标?

我已经用Google搜索过,但是唯一可用的答案是ContextMenuStrips,而不是ContextMenu的.

我想做什么:


Hello!

I have a ContextMenu with assorted items added.

How do I add icons onto these items?

I have googled, but the only available answers deal with ContextMenuStrips, and not ContextMenu''s.

What I want to do:


ContextMenu trayMenu;
trayMenu.MenuItems.Add("Hello");
trayMenu.MenuItems[0].Icon = ....;



不幸的是,.Icon"属性不存在.

请参阅屏幕截图以进行澄清.

我的样子:

http://i52.tinypic.com/5oz586.png [ http://i52.tinypic.com/zx8u1y.png [



Unfortunately the ".Icon" property is non-existent.

See screenshots for clarification.

Mine looks like:

http://i52.tinypic.com/5oz586.png[^]

I want it to look like:

http://i52.tinypic.com/zx8u1y.png[^]

With those icons at the left.

Any help would be greatly appreciated!

推荐答案

为什么不使用ContextMenuStrip?没问题.

您可以使用System.Windows.Forms.MenuStripSystem.Windows.Forms.<code>ContextMenuStrip.对于这些菜单,可以将类System.Windows.Forms.ToolStripMenuItem的实例用于项目.可以使用构造函数ToolStripMenuItem(String, Image)ToolStripMenuItem(String, Image, EventHandler)ToolStripMenuItem(String, Image, ToolStripItem[])用单个图像实例化它.或者,此菜单项可以使用属性ImageKeyImageIndex在图像列表中选择图像,该列表被设置为属性MenuStripContextMenuStrip.该属性是继承的属性System.Windows.Forms.ToolStrip.ImageList.
参见:
http://msdn.microsoft.com/en-us/library/system. windows.forms.toolstrip.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. windows.forms.menustrip.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system. windows.forms.contextmenustrip.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripitem.imageindex.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripitem.imagekey.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripitem.imageindex.aspx [ ^ ].

—SA
Why not using ContextMenuStrip? There is nothing wrong with it.

You can use System.Windows.Forms.MenuStrip or System.Windows.Forms.<code>ContextMenuStrip. For these menus, you can use the instances of the class System.Windows.Forms.ToolStripMenuItem for items. It can be instantiated with individual image using constructors ToolStripMenuItem(String, Image), ToolStripMenuItem(String, Image, EventHandler) or ToolStripMenuItem(String, Image, ToolStripItem[]). Alternatively, this menu item can use property ImageKey or ImageIndex to select the image in the image list, which is set as a property MenuStrip or ContextMenuStrip; the property is inherited property System.Windows.Forms.ToolStrip.ImageList.
See:
http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstrip.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.menustrip.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.contextmenustrip.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripitem.imageindex.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripitem.imagekey.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.toolstripitem.imageindex.aspx[^].

—SA


这篇关于如何在MenuItem中添加图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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