Set the clipping region until instance disposed.
Inheritance: IDisposable
Esempio n. 1
0
        /// <summary>
        ///     Raises the RenderToolStripBackground event.
        /// </summary>
        /// <param name="e">An ToolStripRenderEventArgs containing the event data.</param>
        protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
        {
            if ((e.ToolStrip is ContextMenuStrip) ||
                (e.ToolStrip is ToolStripDropDownMenu))
            {
                // Create border and clipping paths
                using (GraphicsPath borderPath = CreateBorderPath(e.AffectedBounds, _cutContextMenu),
                    clipPath = CreateClipBorderPath(e.AffectedBounds, _cutContextMenu))
                {
                    // Clip all drawing to within the border path
                    using (var clipping = new UseClipping(e.Graphics, clipPath))
                    {
                        // Create the background brush
                        using (var backBrush = new SolidBrush(_contextMenuBack))
                            e.Graphics.FillPath(backBrush, borderPath);
                    }
                }
            }
            else if (e.ToolStrip is StatusStrip)
            {
                // We do not paint the top two pixel lines, so are drawn by the status strip border render method
                var backRect = new RectangleF(0, 1.5f, e.ToolStrip.Width, e.ToolStrip.Height - 2);

                // Cannot paint a zero sized area
                if ((backRect.Width > 0) && (backRect.Height > 0))
                {
                    using (var backBrush = new SolidBrush(_statusBarLight))
                    {
                        //backBrush.Blend = _statusStripBlend;
                        e.Graphics.FillRectangle(backBrush, backRect);
                    }
                    var topRect = new Rectangle(0, 0, (int) backRect.Width, 5);
                    using (
                        var backBrush = new LinearGradientBrush(topRect, _statusBarDark, _statusBarLight,
                            LinearGradientMode.Vertical))
                    {
                        //backBrush.Blend = _statusStripBlend;
                        e.Graphics.FillRectangle(backBrush, topRect);
                    }
                }
            }
            else
            {
                //  base.OnRenderToolStripBackground(e);
                var toolStrip = e.ToolStrip;

                if ((toolStrip.Height > 0) && (toolStrip.Width > 0))
                {
                    var height = toolStrip.Height;
                    var center = height / 2;
                    var width = toolStrip.Width;

                    var topRect = new Rectangle(0, 0, width, center);
                    var bottomRect = new Rectangle(0, center, width, height - center - 3);

                    using (
                        var topBrush = new LinearGradientBrush(topRect, clrWindows7topBegin, clrWindows7topEnd,
                            LinearGradientMode.Vertical))
                        e.Graphics.FillRectangle(topBrush, topRect);

                    using (
                        var bottomBrush = new LinearGradientBrush(bottomRect, clrWindows7bottomBegin,
                            clrWindows7bottomEnd, LinearGradientMode.Vertical))
                        e.Graphics.FillRectangle(bottomBrush, bottomRect);

                    using (var pen3 = new Pen(clrWindows7bottomBorder3))
                        e.Graphics.DrawLine(pen3, 0, height - 3, width, height - 3);

                    using (var pen2 = new Pen(clrWindows7bottomBorder2))
                        e.Graphics.DrawLine(pen2, 0, height - 2, width, height - 2);

                    using (var pen1 = new Pen(clrWindows7bottomBorder1))
                        e.Graphics.DrawLine(pen1, 0, height - 1, width, height - 1);

                    // e.Graphics.FillRectangle(new SolidBrush(clrBGTop2), e.AffectedBounds);

                    // e.Graphics.FillRectangle(bottomGradBrush, bottomGradRect);
                    //    e.Graphics.FillRectangle(horGradBrush, e.AffectedBounds);

                    // e.Graphics.DrawRectangle(new Pen(clrBGBorder, 1), new Rectangle(0, 1, e.ToolStrip.Width - 1, e.ToolStrip.Height - 4));

                    /* using (LinearGradientBrush brush = new LinearGradientBrush(toolStrip.ClientRectangle, Color.FromArgb(253, 253, 253), Color.FromArgb(229, 233, 238), LinearGradientMode.Vertical))
                     {
                         e.Graphics.FillRectangle(brush, 0, 0, toolStrip.Width, toolStrip.Height);
                     }*/
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Raises the RenderToolStripBorder event.
        /// </summary>
        /// <param name="e">An ToolStripRenderEventArgs containing the event data.</param>
        protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
        {
            if ((e.ToolStrip is ContextMenuStrip) ||
                (e.ToolStrip is ToolStripDropDownMenu))
            {
                // If there is a connected area to be drawn
                if (!e.ConnectedArea.IsEmpty)
                    using (var excludeBrush = new SolidBrush(_contextMenuBack))
                        e.Graphics.FillRectangle(excludeBrush, e.ConnectedArea);
                /* var k = e.ToolStrip as ToolStripDropDownMenu;
                 var q = k.Parent;*/
                var connectedArea = Rectangle.Empty;

                // Create border and clipping paths
                using (GraphicsPath borderPath = CreateBorderPath(e.AffectedBounds, connectedArea, _cutContextMenu),
                    insidePath = CreateInsideBorderPath(e.AffectedBounds, connectedArea, _cutContextMenu),
                    clipPath = CreateClipBorderPath(e.AffectedBounds, connectedArea, _cutContextMenu))
                {
                    // Create the different pen colors we need
                    using (Pen borderPen = new Pen(ColorTable.MenuBorder),
                        insidePen = new Pen(_separatorMenuLight))
                    {
                        // Clip all drawing to within the border path
                        using (var clipping = new UseClipping(e.Graphics, clipPath))
                        {
                            // Drawing with anti aliasing to create smoother appearance
                            using (var uaa = new UseAntiAlias(e.Graphics))
                            {
                                // Draw the inside area first
                                e.Graphics.DrawPath(insidePen, insidePath);

                                // Draw the border area second, so any overlapping gives it priority
                                e.Graphics.DrawPath(borderPen, borderPath);
                            }

                            // Draw the pixel at the bottom right of the context menu
                            e.Graphics.DrawLine(borderPen, e.AffectedBounds.Right, e.AffectedBounds.Bottom,
                                e.AffectedBounds.Right - 1, e.AffectedBounds.Bottom - 1);
                        }
                    }
                }
            }
            else if (e.ToolStrip is StatusStrip)
            {
                // Draw two lines at top of the status strip
                /*   using (Pen darkBorder = new Pen(_statusStripBorderDark),
                             lightBorder = new Pen(_statusStripBorderLight))
                   {
                       e.Graphics.DrawLine(darkBorder, 0, 0, e.ToolStrip.Width, 0);
                       e.Graphics.DrawLine(lightBorder, 0, 1, e.ToolStrip.Width, 1);
                   }*/
            }
            else
            {
                //   base.OnRenderToolStripBorder(e);
            }
        }
Esempio n. 3
0
        private void DrawContextMenuHeader(Graphics g, ToolStripItem item)
        {
            // Get the rectangle the is the items area
            var itemRect = new Rectangle(Point.Empty, item.Bounds.Size);

            // Create border and clipping paths
            using (GraphicsPath borderPath = CreateBorderPath(itemRect, _cutToolItemMenu),
                insidePath = CreateInsideBorderPath(itemRect, _cutToolItemMenu),
                clipPath = CreateClipBorderPath(itemRect, _cutToolItemMenu))
            {
                // Clip all drawing to within the border path
                using (var clipping = new UseClipping(g, clipPath))
                {
                    // Draw the entire background area first
                    using (var backBrush = new SolidBrush(_separatorMenuLight))
                        g.FillPath(backBrush, borderPath);

                    // Draw the border
                    using (var borderPen = new Pen(ColorTable.MenuBorder))
                        g.DrawPath(borderPen, borderPath);
                }
            }
        }