Add Icons to Your Menu
Windows applications have been undergoing a gradual facelift since Windows XP and Office XP first appeared on the scene. Today, many modern Windows applications use a fine-tuned menu that sports a blue shaded margin on its left side, and an optional icon for each menu command. (To see what this looks like, you can jump ahead to Figure 3-5.)
Note
Jazz up your dullest menus with thumbnail images.
If you wanted to create a polished-looking menu with this
appearance in .NET 1.0 or 1.1, you needed to draw it yourself using GDI+
code. Although there are several surprisingly good examples of this
technique available on the Internet, it's more than a little messy. In
.NET 2.0, the situation improves dramatically. Even though the original
MainMenu and ContextMenu controls are unchanged, two new
controls—MenuStrip and ContextMenuStrip—provide the same
functionality but render the menu with the new Office XP look.
How do I do that?
The MenuStrip and ContextMenuStrip classes leverage all the
hard work that went into building the ToolStrip class. Essentially, a MenuStrip is a special container for
ToolStripItem objects. The MenuStrip.Items property holds a collection
of top-level menu headings (like File, Edit, View, and Help), each of
which is represented by a ToolStripMenuItem object. Each ToolStripMenuItem has a DropDownItemsProperty, which exposes another
collection of ToolStripMenuItem
objects, one for each contained menu item.
Example 3-2 shows code that creates ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access