Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
457 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...