Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put an icon in a MenuItem

Tags:

Is there a way to put an icon next to the text in a MenuItem?

I use the following code to display a popup menu when the user right clicks in a user control:

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

I would like to put a icon to the left of the "test" string in the popup menu so that the user more easily recognizes it. Is there a way to do this other than by setting the OwnerDraw property to true (thus requiring me to completely draw the menu item myself, like it is done in this example: http://www.codeproject.com/KB/menus/cs_menus.aspx)?

Any help is appreciated.

like image 633
Bart Gijssens Avatar asked Jul 08 '11 11:07

Bart Gijssens


People also ask

How to add icon in menu WordPress?

Find the right menu and add an icon To add WordPress menu icons, select any of the menu items you already have created. Locate the Icon: Select link. Click on that to navigate to the section to add an icon to that particular menu item.

Which class is used to set icons in menu items?

We can do this by adding the menu-item-float-right class to the menu item. First, make sure the CSS Classes field is enabled by clicking on Screen Options at the top right of the menu page, and checking the CSS Classes field. Then expand your menu item, and give it that menu-item-float-right class.


1 Answers

Try using ContextMenuStrip and add ToolStripMenuItems to it.

If you have to use MenuItem, you will have to do it through the DrawItem event with the OwnerDraw property set to true.

like image 69
LarsTech Avatar answered Oct 03 '22 22:10

LarsTech