My Windows Forms application has a MenuStrip
and some of the menu items (ToolStripMenuItem
) have an icon (setting the ToolStripMenuItem.Image
property).
When the RenderMode
property of the MenuStrip
is set to ToolStripRenderMode.System
, the checkmark doesn't display when the Checked
or CheckOnClick
property is true and the menu item has an icon.
It does display when i switch the MenuStrip.RenderMode
property to ToolStripRenderMode.Professional
or ToolStripRenderMode.RenderManagerMode
.
Unfortunately, this is a problem because my app requires:
- A
ProgressBar
in marquee mode, soApplication.EnableVisualStyles()
is required to get this to work. - The app requires a "flat" visual style, which i accomplished by leaving out the call to
Application.EnableVisualStyles()
and leaving the defaultToolStripRenderMode.RenderManagerMode
on the MenuStrip. But then i can't get my marquee ProgressBar! - Setting the
RenderMode
toToolStripRenderMode.System
solves the look and feel requirement, but takes away the ability to have checked menu items w/icons.
Is there any way to satisfy all my requirements? Am i missing something? Thanks for looking.
Wow, i stumped SO! Now i know i must be working on some serious code.
Anyway, the answer is: implement your own
ToolStripRenderer
by creating a class that inherits fromToolStripSystemRenderer
.Override the methods that draw the items with your own code. Here's what i was looking for specifically that draws the checked item. It draws a check if there's no image for the
ToolStripMenuItem
.I did also come across a simpler alternative:
You can simply put your menu items into a ContextMenuStrip and then assign it to the DropDown property of the DropDownButton.
Hope this helps anyone out there who doesn't fancy overriding the Paint method.