BUG: The DrawItemEventArgs object returns incorrect ForeColor and BackColor properties for owner-draw menu items (834530)
The information in this article applies to:
- Microsoft .NET Framework 1.1
- Microsoft .NET Framework 1.0
SYMPTOMSWhen you owner-draw menu items, the color of the menu
background and of the menu text is not correct. Although you defined
a color scheme for the Menu item in the Display Properties dialog box, the
color scheme for the Window item is used.CAUSEThis problem occurs because the DrawItemEventArgs object does not return the correct information for the ForeColor property and the BackColor property for owner-draw menu items.STATUSMicrosoft has confirmed that this is a bug in the Microsoft
products that are listed in the "Applies to" section of this
article.WORKAROUNDTo work around this problem, construct a new DrawItemEventArgs object that is based on the e parameter in the DrawItem event handler: private void menuItem2_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
DrawItemEventArgs dea=new DrawItemEventArgs(e.Graphics,e.Font,e.Bounds,e.Index,e.State, SystemColors.MenuText,SystemColors.Menu);
dea.DrawBackground ();
ControlPaint.DrawMenuGlyph(dea.Graphics, 2, 2, 14, 14, MenuGlyph.Checkmark);
SolidBrush sb = new SolidBrush (dea.ForeColor);
dea.Graphics.DrawString ("Open", dea.Font, sb,dea.Bounds.Left + 18, dea.Bounds.Top + 2);
sb.Dispose ();
}
Note Although this workaround fixes the background color and the
foreground color of the menu item, the checkmark is still the wrong
color.
Modification Type: | Major | Last Reviewed: | 3/2/2004 |
---|
Keywords: | kbcode kbBug kbGDIPlus kbWindowsForms KB834530 kbAudDeveloper |
---|
|