private void DrawImage(Graphics graphics, Rectangle bounds, bool selected, bool disabled)
{
Rectangle rectangle = new Rectangle(bounds.X, bounds.Y, imageSize.Width + 6, bounds.Height);
Size checkSize = SystemInformation.MenuCheckSize;
Rectangle checkRectangle = new Rectangle(bounds.X + 1 + ((imageSize.Width + 6 - checkSize.Width) / 2), bounds.Y + ((bounds.Height - checkSize.Height) / 2), checkSize.Width, checkSize.Height);
CommandBarCheckBox checkBox = item as CommandBarCheckBox;
if (this.IsFlatMenu)
{
DrawBackground(graphics, rectangle, selected);
if ((checkBox != null) && (checkBox.IsChecked))
{
int height = bounds.Height - 2;
graphics.DrawRectangle(SystemPens.Highlight, new Rectangle(bounds.X + 1, bounds.Y + 1, imageSize.Width + 3, height - 1));
graphics.FillRectangle(SystemBrushes.Menu, new Rectangle(bounds.X + 2, bounds.Y + 2, imageSize.Width + 2, height - 2));
}
Image image = item.Image;
if (image != null)
{
Point point = new Point(bounds.X + 3, bounds.Y + ((bounds.Height - image.Height) / 2));
NativeMethods.DrawImage(graphics, image, point, disabled);
}
else
{
if ((checkBox != null) && (checkBox.IsChecked))
{
Color color = (disabled ? SystemColors.GrayText : SystemColors.MenuText);
this.DrawCheck(graphics, checkRectangle, color);
}
}
}
else
{
Image image = item.Image;
if (image == null)
{
this.DrawBackground(graphics, rectangle, selected);
if ((checkBox != null) && (checkBox.IsChecked))
{
Color color = (disabled ? (selected ? SystemColors.GrayText : SystemColors.ControlDark) : (selected ? SystemColors.HighlightText : SystemColors.MenuText));
this.DrawCheck(graphics, checkRectangle, color);
}
}
else
{
DrawBackground(graphics, rectangle, false);
if ((checkBox != null) && (checkBox.IsChecked))
{
ControlPaint.DrawBorder3D(graphics, rectangle, Border3DStyle.SunkenOuter);
}
else if (selected)
{
ControlPaint.DrawBorder3D(graphics, rectangle, Border3DStyle.RaisedInner);
}
Point point = new Point(bounds.X + 3, bounds.Y + ((bounds.Height - image.Height) / 2));
NativeMethods.DrawImage(graphics, image, point, disabled);
}
}
}