How to change the menu highlight color in C# 2.0?

Jack Brown <[email protected]> Tue, 19 Feb 2008 11:57:10 -0800
Newsgroups gmane.comp.windows.devel.dotnet.winforms
Message-ID <1367B16B94997E418CDDC01D1BDEF17904F0CCC0@ei-postal.EI.Electroimpact.com>
I've run into a problem that I can't find a solution to. I've got custom
colors set in the Windows XP Appearances setting for menus and selected
menu items.

I have menu bars set to a purple background and yellow text. (As close
as I can get to purple and gold for the UW Huskies. :) The selected item
colors are reversed. Yellow for the background and purple for the text.
Works great in programs like Firefox, Thunderbird, etc.

I've added a MenuStrip and several ToolStripMenuItem to a form. I set
the BackColor to System.Drawing.SystemColors.Menu and the ForeColor to
System.Drawing.SystemColors.MenuText.

If I click on the menu or any of the menu items, they generally display
nicely with the colors. Except for the highlight color on item the mouse
is currently over. That highlight color is always a light grey and the
color of the text stays yellow. Very low contrast is nearly impossible
to read.

Is there some way to change that highlight color? I've googled
references to changing in via OwnerDraw for TreeView controls, but
nothing for menu items. The menu items don't have a DrawMode or
OwnerDraw property that I can find.

I can use the MouseEnter and Leave events to change the fore and back
colors like this:

                private void toolStripMenuItem_Enter( object sender,
EventArgs e )
                {
                        ToolStripMenuItem blah =3D
(ToolStripMenuItem)sender;
                        blah.BackColor =3D
System.Drawing.SystemColors.MenuText;
                        blah.ForeColor =3D
System.Drawing.SystemColors.Menu;
                }
                private void toolStripMenuItem_Leave( object sender,
EventArgs e )
                {
                        ToolStripMenuItem blah =3D
(ToolStripMenuItem)sender;
                        blah.BackColor =3D
System.Drawing.SystemColors.Menu;
                        blah.ForeColor =3D
System.Drawing.SystemColors.MenuText;
                }

But, the blasted highlight color is still the light grey. At least the
text is readable this way, but it still looks like garbage.

Please, if this isn't clear, ask for clarification.

Thanks.

Jack Brown
Controls Engineer
Electroimpact, Inc.
[email protected]
(W)425-609-4988
(C)206-617-6482