Set the SmoothingMode=AntiAlias until instance disposed.
Inheritance: IDisposable
Exemplo n.º 1
0
        /// <summary>
        ///     Raises the RenderItemCheck event.
        /// </summary>
        /// <param name="e">An ToolStripItemImageRenderEventArgs containing the event data.</param>
        protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e)
        {
            // Staring size of the checkbox is the image rectangle
            var checkBox = e.ImageRectangle;

            // Make the border of the check box 1 pixel bigger on all sides, as a minimum
            checkBox.Inflate(2, 2);

            // Can we extend upwards?
            if (checkBox.Top > _checkInset)
            {
                var diff = checkBox.Top - _checkInset;
                checkBox.Y -= diff;
                checkBox.Height += diff;
            }

            // Can we extend downwards?
            if (checkBox.Height <= (e.Item.Bounds.Height - (_checkInset * 2)))
            {
                var diff = e.Item.Bounds.Height - (_checkInset * 2) - checkBox.Height;
                checkBox.Height += diff;
            }

            checkBox.Width = checkBox.Height;

            // Drawing with anti aliasing to create smoother appearance
            using (var uaa = new UseAntiAlias(e.Graphics))
            {
                // Create border path for the check box
                using (var borderPath = CreateBorderPath(checkBox, _cutMenuItemBack))
                {
                    // Fill the background in a solid color
                    using (var fillBrush = new SolidBrush(ColorTable.CheckBackground))
                        e.Graphics.FillPath(fillBrush, borderPath);

                    // Draw the border around the check box
                    using (var borderPen = new Pen(_contextCheckBorder))
                        e.Graphics.DrawPath(borderPen, borderPath);

                    // If there is not an image, then we can draw the tick, square etc...
                    if (e.Image != null)
                    {
                        var checkState = CheckState.Unchecked;

                        // Extract the check state from the item
                        if (e.Item is ToolStripMenuItem)
                        {
                            var item = (ToolStripMenuItem) e.Item;
                            checkState = item.CheckState;
                        }

                        // Decide what graphic to draw
                        switch (checkState)
                        {
                            case CheckState.Checked:
                                // Create a path for the tick
                                using (var tickPath = CreateTickPath(checkBox))
                                {
                                    // Draw the tick with a thickish brush
                                    using (var tickPen = new Pen(_contextCheckTick, _contextCheckTickThickness))
                                        e.Graphics.DrawPath(tickPen, tickPath);
                                }
                                break;
                            case CheckState.Indeterminate:
                                // Create a path for the indeterminate diamond
                                using (var tickPath = CreateIndeterminatePath(checkBox))
                                {
                                    // Draw the tick with a thickish brush
                                    using (var tickBrush = new SolidBrush(_contextCheckTick))
                                        e.Graphics.FillPath(tickBrush, tickPath);
                                }
                                break;
                        }
                    }
                }
            }
        }
Exemplo 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);
            }
        }
Exemplo n.º 3
0
        private void DrawGradientBorder(Graphics g,
            Rectangle backRect,
            GradientItemColors colors)
        {
            // Drawing with anti aliasing to create smoother appearance
            using (var uaa = new UseAntiAlias(g))
            {
                var backRectI = backRect;
                backRectI.Inflate(1, 1);

                // Finally draw the border around the menu item
                using (
                    var borderBrush = new LinearGradientBrush(backRectI, colors.Border1, colors.Border2,
                        90f))
                {
                    // Sigma curve, so go from color1 to color2 and back to color1 again
                    borderBrush.SetSigmaBellShape(0.5f);

                    // Convert the brush to a pen for DrawPath call
                    using (var borderPen = new Pen(borderBrush))
                    {
                        // Create border path around the entire item
                        using (var borderPath = CreateBorderPath(backRect, _cutMenuItemBack))
                            g.DrawPath(borderPen, borderPath);
                    }
                }
            }
        }