public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e)
{
StringFormat string_format;
Rectangle rect_text = e.Bounds;
if (item.Visible == false)
return;
if (item.MenuBar)
string_format = string_format_menu_menubar_text;
else
string_format = string_format_menu_text;
if (item.Separator == true) {
int liney = e.Bounds.Y + (e.Bounds.Height / 2);
e.Graphics.DrawLine (SystemPens.ControlDark,
e.Bounds.X, liney, e.Bounds.X + e.Bounds.Width, liney);
e.Graphics.DrawLine (SystemPens.ControlLight,
e.Bounds.X, liney + 1, e.Bounds.X + e.Bounds.Width, liney + 1);
return;
}
if (!item.MenuBar)
rect_text.X += MenuCheckSize.Width;
if (item.BarBreak) { /* Draw vertical break bar*/
Rectangle rect = e.Bounds;
rect.Y++;
rect.Width = 3;
rect.Height = item.MenuHeight - 6;
e.Graphics.DrawLine (SystemPens.ControlDark,
rect.X, rect.Y , rect.X, rect.Y + rect.Height);
e.Graphics.DrawLine (SystemPens.ControlLight,
rect.X + 1, rect.Y , rect.X +1, rect.Y + rect.Height);
}
Color color_text;
Color color_back;
Brush brush_text = null;
Brush brush_back = null;
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected && !item.MenuBar) {
color_text = ColorHighlightText;
color_back = ColorHighlight;
brush_text = SystemBrushes.HighlightText;
brush_back = SystemBrushes.Highlight;
} else {
color_text = ColorMenuText;
color_back = ColorMenu;
brush_text = ResPool.GetSolidBrush (ColorMenuText);
brush_back = SystemBrushes.Menu;
}
/* Draw background */
if (!item.MenuBar)
e.Graphics.FillRectangle (brush_back, e.Bounds);
if (item.Enabled) {
e.Graphics.DrawString (item.Text, e.Font,
brush_text,
rect_text, string_format);
if (item.MenuBar) {
Border3DStyle border_style = Border3DStyle.Adjust;
if ((item.Status & DrawItemState.HotLight) != 0)
border_style = Border3DStyle.RaisedInner;
else if ((item.Status & DrawItemState.Selected) != 0)
border_style = Border3DStyle.SunkenOuter;
if (border_style != Border3DStyle.Adjust)
CPDrawBorder3D(e.Graphics, e.Bounds, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, ColorMenu);
}
} else {
if ((item.Status & DrawItemState.Selected) != DrawItemState.Selected) {
e.Graphics.DrawString (item.Text, e.Font, Brushes.White,
new RectangleF(rect_text.X + 1, rect_text.Y + 1, rect_text.Width, rect_text.Height),
string_format);
}
e.Graphics.DrawString (item.Text, e.Font, ResPool.GetSolidBrush(ColorGrayText), rect_text, string_format);
}
if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) {
string str = item.GetShortCutText ();
Rectangle rect = rect_text;
rect.X = item.XTab;
rect.Width -= item.XTab;
if (item.Enabled) {
e.Graphics.DrawString (str, e.Font, brush_text, rect, string_format_menu_shortcut);
} else {
if ((item.Status & DrawItemState.Selected) != DrawItemState.Selected) {
e.Graphics.DrawString (str, e.Font, Brushes.White,
new RectangleF(rect.X + 1, rect.Y + 1, rect.Width, rect_text.Height),
string_format_menu_shortcut);
}
e.Graphics.DrawString (str, e.Font, ResPool.GetSolidBrush(ColorGrayText), rect, string_format_menu_shortcut);
}
}
/* Draw arrow */
if (item.MenuBar == false && (item.IsPopup || item.MdiList)) {
int cx = MenuCheckSize.Width;
int cy = MenuCheckSize.Height;
Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), MenuGlyph.Arrow, color_text);
if (item.Enabled) {
e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx,
e.Bounds.Y + ((e.Bounds.Height - cy) /2));
} else {
ControlPaint.DrawImageDisabled (e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
e.Bounds.Y + ((e.Bounds.Height - cy) /2), color_back);
}
bmp.Dispose ();
}
/* Draw checked or radio */
if (item.MenuBar == false && item.Checked) {
Rectangle area = e.Bounds;
int cx = MenuCheckSize.Width;
int cy = MenuCheckSize.Height;
Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), item.RadioCheck ? MenuGlyph.Bullet : MenuGlyph.Checkmark, color_text);
e.Graphics.DrawImage (bmp, area.X, e.Bounds.Y + ((e.Bounds.Height - cy) / 2));
bmp.Dispose ();
}
}