有没有办法在MenuItem中的文本旁边放置图标?

当用户右键单击用户控件时,我使用以下代码显示弹出菜单:

 ContextMenu menu = new ContextMenu();
 MenuItem item = new MenuItem("test", OnClick);
 menu.MenuItems.Add(item);
 menu.Show(this, this.PointToClient(MousePosition));

我想在弹出菜单中的“测试”字符串的左侧放置一个图标,以便用户更容易识别它。除了将OwnerDraw属性设置为true之外,还有其他方法可以做到这一点(因此需要我自己完全绘制菜单项,就像在此示例中一样:http://www.codeproject.com/KB/menus/cs_menus.aspx)?

任何帮助表示赞赏。

最佳答案

尝试使用ContextMenuStrip并向其中添加ToolStripMenuItems。

如果必须使用MenuItem,则必须通过DrawItem事件(将OwnerDraw属性设置为true)来执行此操作。

关于c# - 如何在MenuItem中放置图标,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6623672/

10-13 07:55