protected override void OnRenderItemImage(ToolStripItemImageRenderEventArgs e)
{
//base.OnRenderItemImage(e);
int offset = 28;
Image icon = e.Image;
Rectangle iconRect = e.ImageRectangle;
Graphics g = e.Graphics;
if (e.ToolStrip is ContextMenuStrip)
{
ContextMenuStrip contextMenuStrip = e.ToolStrip as ContextMenuStrip;
iconRect.X = (offset - icon.Width) / 2;
if (icon.Width < contextMenuStrip.ImageScalingSize.Width ||
icon.Height < contextMenuStrip.ImageScalingSize.Height)
{
g.DrawImage(icon, iconRect);
}
else
{
Rectangle iconPoint = new Rectangle(
iconRect.X,
2,
contextMenuStrip.ImageScalingSize.Width + 3,
contextMenuStrip.ImageScalingSize.Height + 2);
Rectangle imgRect = new Rectangle(0, 0, icon.Width, icon.Height);
g.DrawImage(icon, iconPoint, imgRect, GraphicsUnit.Pixel);
}
}
}