protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
        {
            ToolStripButton item   = e.Item as ToolStripButton;
            Graphics        g      = e.Graphics;
            Rectangle       bounds = new Rectangle(Point.Empty, item.Size);

            if (item.CheckState == CheckState.Unchecked)
            {
                RenderItemInternal(e, /*useHotBorder = */ true);
            }
            else
            {
                Rectangle fillRect = (item.Selected) ? item.ContentRectangle : bounds;

                if (item.BackgroundImage != null)
                {
                    MyControlPaint.DrawBackgroundImage(g, item.BackgroundImage, item.BackColor, item.BackgroundImageLayout, bounds, fillRect);
                }

                if (UseSystemColors)
                {
                    if (item.Selected)
                    {
                        RenderPressedButtonFill(g, bounds);
                    }
                    else
                    {
                        RenderCheckedButtonFill(g, bounds);
                    }

                    using (Pen p = new Pen(ColorTable.ButtonSelectedBorder))
                    {
                        g.DrawRectangle(p, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
                    }
                }
                else
                {
                    if (item.Selected)
                    {
                        RenderPressedButtonFill(g, bounds);
                    }
                    else
                    {
                        RenderCheckedButtonFill(g, bounds);
                    }
                    using (Pen p = new Pen(ColorTable.ButtonSelectedBorder))
                    {
                        g.DrawRectangle(p, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
                    }
                }
            }
        }
        private void RenderItemInternal(ToolStripItemRenderEventArgs e, bool useHotBorder)
        {
            Graphics      g             = e.Graphics;
            ToolStripItem item          = e.Item;
            Rectangle     bounds        = new Rectangle(Point.Empty, item.Size);
            bool          drawHotBorder = false;

            Rectangle fillRect = (item.Selected) ? item.ContentRectangle : bounds;

            if (item.BackgroundImage != null)
            {
                MyControlPaint.DrawBackgroundImage(g, item.BackgroundImage, item.BackColor, item.BackgroundImageLayout, bounds, fillRect);
            }

            if (item.Pressed)
            {
                RenderPressedButtonFill(g, bounds);
                drawHotBorder = useHotBorder;
            }
            else if (item.Selected)
            {
                RenderSelectedButtonFill(g, bounds);
                drawHotBorder = useHotBorder;
            }
            else if (item.Owner != null && item.BackColor != item.Owner.BackColor)
            {
                using (Brush b = new SolidBrush(item.BackColor))
                {
                    g.FillRectangle(b, bounds);
                }
            }

            if (drawHotBorder)
            {
                using (Pen p = new Pen(ColorTable.ButtonSelectedBorder))
                {
                    g.DrawRectangle(p, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
                }
            }
        }
        protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
        {
            ToolStripItem item   = e.Item;
            Graphics      g      = e.Graphics;
            Rectangle     bounds = new Rectangle(Point.Empty, item.Size);

            if ((bounds.Width == 0) || (bounds.Height == 0))
            {
                return;  // can't new up a linear gradient brush with no dimension.
            }

            //ControlBoxMenuItem
            bool itemIsControlBoxMenuItem = item.GetType().Name == "ControlBoxMenuItem";

            if (itemIsControlBoxMenuItem)
            {
                if (item.BackColor != SystemColors.Control)
                {
                    item.BackColor = SystemColors.Control;
                }
            }

            if (item.GetType().Name == "MdiControlStrip")
            {
                return; // no highlights are painted behind a system menu item
            }


            if (item.IsOnDropDown)
            {
                bounds = MyControlPaint.DeflateRect(bounds, dropDownMenuItemPaintPadding);

                if (item.Selected)
                {
                    Color borderColor = ColorTable.MenuItemBorder;
                    if (item.Enabled)
                    {
                        if (UseSystemColors)
                        {
                            borderColor = SystemColors.Highlight;
                            RenderSelectedButtonFill(g, bounds);
                        }
                        else
                        {
                            using (Brush b = new SolidBrush(ColorTable.MenuItemSelected))
                            {
                                g.FillRectangle(b, bounds);
                            }
                        }
                    }
                    // draw selection border - always drawn regardless of Enabled.
                    using (Pen p = new Pen(borderColor))
                    {
                        g.DrawRectangle(p, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
                    }
                }
                else
                {
                    Rectangle fillRect = bounds;


                    if (item.BackgroundImage != null)
                    {
                        MyControlPaint.DrawBackgroundImage(g, item.BackgroundImage, item.BackColor, item.BackgroundImageLayout, bounds, fillRect);
                    }
                    else
                    if (item.Owner != null && item.BackColor != item.Owner.BackColor)
                    {
                        using (Brush b = new SolidBrush(item.BackColor))
                        {
                            g.FillRectangle(b, fillRect);
                        }
                    }
                }
            }
            else
            {
                if (item.Pressed)
                {
                    // Toplevel toolstrip rendering
                    RenderPressedGradient(g, bounds);
                }
                else if (item.Selected)
                {
                    //Hot, Pressed behavior
                    // Fill with orange
                    Color borderColor = ColorTable.MenuItemBorder;

                    if (item.Enabled)
                    {
                        if (itemIsControlBoxMenuItem)
                        {
                            borderColor = SystemColors.Highlight;
                            RenderSelectedButtonFill(g, bounds, SystemColors.ButtonHighlight);
                        }
                        else if (UseSystemColors)
                        {
                            borderColor = SystemColors.Highlight;
                            RenderSelectedButtonFill(g, bounds);
                        }
                        else
                        {
                            using (Brush b = new LinearGradientBrush(bounds, ColorTable.MenuItemSelectedGradientBegin, ColorTable.MenuItemSelectedGradientEnd, LinearGradientMode.Vertical))
                            {
                                g.FillRectangle(b, bounds);
                            }
                        }
                    }

                    // draw selection border - always drawn regardless of Enabled.
                    using (Pen p = new Pen(borderColor))
                    {
                        g.DrawRectangle(p, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
                    }
                }
                else
                {
                    Rectangle fillRect = bounds;


                    if (item.BackgroundImage != null)
                    {
                        MyControlPaint.DrawBackgroundImage(g, item.BackgroundImage, item.BackColor, item.BackgroundImageLayout, bounds, fillRect);
                    }
                    else
                    if (item.Owner != null && item.BackColor != item.Owner.BackColor)
                    {
                        using (Brush b = new SolidBrush(item.BackColor))
                        {
                            g.FillRectangle(b, fillRect);
                        }
                    }
                }
            }
        }