Esempio n. 1
0
	void MainForm_Paint (object sender, PaintEventArgs e)
	{
		Graphics g = e.Graphics;
		GraphicsPath path = new GraphicsPath ();

		Rectangle borderect = new Rectangle (49, 49, 252, 252);
		g.FillRectangle (new SolidBrush (Color.White), borderect);

		int Diameter = 16;
		Rectangle baserect = new Rectangle (50, 50, 249, 249);

		Rectangle arcrect = new Rectangle (baserect.Location, new Size (Diameter, Diameter));

		// handle top left corner
		path.AddArc (arcrect, 180, 90);

		// handle top right corner
		arcrect.X = baserect.Right - Diameter;
		path.AddArc (arcrect, 270, 90);

		// handle baserect right corner
		arcrect.Y = baserect.Bottom - Diameter;
		path.AddArc (arcrect, 0, 90);

		// handle bottom left corner
		arcrect.X = baserect.Left;
		path.AddArc (arcrect, 90, 90);

		path.CloseFigure ();

		g.DrawPath (Pens.SteelBlue, path);
	}
Esempio n. 2
0
 static internal GraphicsPath CreateRound(Rectangle r, int slope)
 {
     CreateRoundPath = new GraphicsPath(FillMode.Winding);
     CreateRoundPath.AddArc(r.X, r.Y, slope, slope, 180f, 90f);
     CreateRoundPath.AddArc(r.Right - slope, r.Y, slope, slope, 270f, 90f);
     CreateRoundPath.AddArc(r.Right - slope, r.Bottom - slope, slope, slope, 0f, 90f);
     CreateRoundPath.AddArc(r.X, r.Bottom - slope, slope, slope, 90f, 90f);
     CreateRoundPath.CloseFigure();
     return CreateRoundPath;
 }
Esempio n. 3
0
 public static GraphicsPath RoundRect(Rectangle rect, int Curve)
 {
     GraphicsPath P = new GraphicsPath();
     int ArcRectWidth = Curve * 2;
     P.AddArc(new Rectangle(rect.X, rect.Y, ArcRectWidth, ArcRectWidth), -180, 90);
     P.AddArc(new Rectangle(rect.Width - ArcRectWidth + rect.X, rect.Y, ArcRectWidth, ArcRectWidth), -90, 90);
     P.AddArc(new Rectangle(rect.Width - ArcRectWidth + rect.X, rect.Height - ArcRectWidth + rect.Y, ArcRectWidth, ArcRectWidth), 0, 90);
     P.AddArc(new Rectangle(rect.X, rect.Height - ArcRectWidth + rect.Y, ArcRectWidth, ArcRectWidth), 90, 90);
     P.AddLine(new Point(rect.X, rect.Height - ArcRectWidth + rect.Y), new Point(rect.X, Curve + rect.Y));
     return P;
 }
Esempio n. 4
0
    protected override void OnResize(EventArgs e)
    {
        Height = 19; Width = 47;
        
        RoundedRectangle = new GraphicsPath();
        int radius = 10;

        RoundedRectangle.AddArc(11, 4, radius - 1, radius, 180, 90);
        RoundedRectangle.AddArc(Width - 21, 4, radius - 1, radius, -90, 90);
        RoundedRectangle.AddArc(Width - 21, Height - 15, radius - 1, radius, 0, 90);
        RoundedRectangle.AddArc(11, Height - 15, radius - 1, radius, 90, 90);

        RoundedRectangle.CloseAllFigures();
        Invalidate(); 
    }
Esempio n. 5
0
	void MainForm_Load (object sender, EventArgs e)
	{
		GraphicsPath gp = new GraphicsPath ();
		gp.AddArc (_changeShapeButton.ClientRectangle, 0.0f, 360.0f);
		_changeShapeButton.Region = new Region (gp);

		InstructionsForm instructionsForm = new InstructionsForm ();
		instructionsForm.Show ();
	}
Esempio n. 6
0
    public static GraphicsPath CreateRoundRect(float x, float y, float width, float height, float radius)
    {
        GraphicsPath gp = new GraphicsPath();
        gp.AddLine(x + radius, y, x + width - (radius * 2), y);
        gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90);

        gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2));
        gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90);

        gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height);
        gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90);

        gp.AddLine(x, y + height - (radius * 2), x, y + radius);
        gp.AddArc(x, y, radius * 2, radius * 2, 180, 90);

        gp.CloseFigure();
        return gp;
    }
Esempio n. 7
0
    public static GraphicsPath CreateRoundedRectangle(SizeF size, PointF location)
    {
        int cornerSize			= (int)GraphConstants.CornerSize * 2;

        var height				= size.Height;
        var width				= size.Width;
        var left				= location.X;
        var top					= location.Y;
        var right				= location.X + width;
        var bottom				= location.Y + height;

        var path = new GraphicsPath(FillMode.Winding);
        path.AddArc(left, top, cornerSize, cornerSize, 180, 90);
        path.AddArc(right - cornerSize, top, cornerSize, cornerSize, 270, 90);

        path.AddArc(right - cornerSize, bottom - cornerSize, cornerSize, cornerSize, 0, 90);
        path.AddArc(left, bottom - cornerSize, cornerSize, cornerSize, 90, 90);
        path.CloseFigure();
        return path;
    }
Esempio n. 8
0
    /// <summary>
    /// Creates the round rect path.
    /// </summary>
    /// <param name="rect">The rectangle on which graphics path will be spanned.</param>
    /// <param name="size">The size of rounded rectangle edges.</param>
    /// <returns></returns>
    public static GraphicsPath CreateRoundRectPath(Rectangle rect, Size size)
    {
        GraphicsPath gp = new GraphicsPath();
        gp.AddLine(rect.Left + size.Width / 2, rect.Top, rect.Right - size.Width / 2, rect.Top);
        gp.AddArc(rect.Right - size.Width, rect.Top, size.Width, size.Height, 270, 90);

        gp.AddLine(rect.Right, rect.Top + size.Height / 2, rect.Right, rect.Bottom - size.Width / 2);
        gp.AddArc(rect.Right - size.Width, rect.Bottom - size.Height, size.Width, size.Height, 0, 90);

        gp.AddLine(rect.Right - size.Width / 2, rect.Bottom, rect.Left + size.Width / 2, rect.Bottom);
        gp.AddArc(rect.Left, rect.Bottom - size.Height, size.Width, size.Height, 90, 90);

        gp.AddLine(rect.Left, rect.Bottom - size.Height / 2, rect.Left, rect.Top + size.Height / 2);
        gp.AddArc(rect.Left, rect.Top, size.Width, size.Height, 180, 90);
        return gp;
    }
Esempio n. 9
0
        public static GraphicsPath GetRoundedRect(Rectangle baseRect, int radius)
        {
            //float x = baseRect.X, y = baseRect.Y, w = baseRect.Width, h = baseRect.Height;
            //GraphicsPath rr = new GraphicsPath();

            //rr.AddBezier(x, y + radius, x, y, x + radius, y, x + radius, y);
            //rr.AddLine(x + radius, y, x + w - radius, y);
            //rr.AddBezier(x + w - radius, y, x + w, y, x + w, y + radius, x + w, y + radius);
            //rr.AddLine(x + w, y + radius, x + w, y + h - radius);
            //rr.AddBezier(x + w, y + h - radius, x + w, y + h, x + w - radius, y + h, x + w - radius, y + h);
            //rr.AddLine(x + w - radius, y + h, x + radius, y + h);
            //rr.AddBezier(x + radius, y + h, x, y + h, x, y + h - radius, x, y + h - radius);
            //rr.AddLine(x, y + h - radius, x, y + radius);

            //return rr;
            GraphicsPath path = new GraphicsPath();

            if (radius <= 0)
            {
                path.AddRectangle(baseRect);
            }
            else if (radius >= (Math.Min(baseRect.Width, baseRect.Height)) / 2)
            {
                if (baseRect.Width > baseRect.Height)
                {
                    // return horizontal capsule
                    int       diameter = baseRect.Height;
                    Rectangle arc      = new Rectangle(baseRect.Location, new Size(diameter, diameter));

                    path.AddArc(arc, 90, 180);
                    arc.X = baseRect.Right - diameter;
                    path.AddArc(arc, 270, 180);
                }
                else if (baseRect.Width < baseRect.Height)
                {
                    // return vertical capsule
                    int       diameter = baseRect.Width;
                    Rectangle arc      = new Rectangle(baseRect.Location, new Size(diameter, diameter));

                    path.AddArc(arc, 180, 180);
                    arc.Y = baseRect.Bottom - diameter;
                    path.AddArc(arc, 0, 180);
                }
                else
                {
                    // return circle
                    path.AddEllipse(baseRect);
                }
            }
            else
            {
                int       diameter = radius * 2;
                Rectangle arc      = new Rectangle(baseRect.Location, new Size(diameter, diameter));

                // top left arc
                path.AddArc(arc, 180, 90);

                // top right arc
                arc.X = baseRect.Right - diameter;
                path.AddArc(arc, 270, 90);

                // bottom right arc
                arc.Y = baseRect.Bottom - diameter;
                path.AddArc(arc, 0, 90);

                // bottom left arc
                arc.X = baseRect.Left;
                path.AddArc(arc, 90, 90);
            }

            path.CloseFigure();
            return(path);
        }
Esempio n. 10
0
        static void Render(Graphics graphics, Node node)
        {
            var size     = node.bounds.Size;
            var position = node.bounds.Location;

            int cornerSize        = (int)GraphConstants.CornerSize * 2;
            int connectorSize     = (int)GraphConstants.ConnectorSize;
            int halfConnectorSize = (int)Math.Ceiling(connectorSize / 2.0f);
            var connectorOffset   = (int)Math.Floor((GraphConstants.MinimumItemHeight - GraphConstants.ConnectorSize) / 2.0f);
            var left   = position.X + halfConnectorSize;
            var top    = position.Y;
            var right  = position.X + size.Width - halfConnectorSize;
            var bottom = position.Y + size.Height;

            using (var path = new GraphicsPath(FillMode.Winding))
            {
                path.AddArc(left, top, cornerSize, cornerSize, 180, 90);
                path.AddArc(right - cornerSize, top, cornerSize, cornerSize, 270, 90);

                path.AddArc(right - cornerSize, bottom - cornerSize, cornerSize, cornerSize, 0, 90);
                path.AddArc(left, bottom - cornerSize, cornerSize, cornerSize, 90, 90);
                path.CloseFigure();

                if ((node.state & (RenderState.Dragging | RenderState.Focus)) != 0)
                {
                    graphics.FillPath(Brushes.DarkOrange, path);
                }
                else
                if ((node.state & RenderState.Hover) != 0)
                {
                    graphics.FillPath(Brushes.LightSteelBlue, path);
                }
                else
                {
                    graphics.FillPath(Brushes.LightGray, path);
                }
                graphics.DrawPath(BorderPen, path);
            }

            /*
             * if (!node.Collapsed)
             *      graphics.DrawLine(Pens.Black,
             *              left  + GraphConstants.ConnectorSize, node.titleItem.bounds.Bottom - GraphConstants.ItemSpacing,
             *              right - GraphConstants.ConnectorSize, node.titleItem.bounds.Bottom - GraphConstants.ItemSpacing);
             */
            var itemPosition = position;

            itemPosition.X += connectorSize + (int)GraphConstants.HorizontalSpacing;
            if (node.Collapsed)
            {
                bool inputConnected = false;
                var  inputState     = RenderState.None;
                var  outputState    = node.outputState;
                foreach (var connection in node.connections)
                {
                    if (connection.To.Node == node)
                    {
                        inputState    |= connection.state;
                        inputConnected = true;
                    }
                    if (connection.From.Node == node)
                    {
                        outputState |= connection.state | RenderState.Connected;
                    }
                }

                RenderItem(graphics, new SizeF(node.bounds.Width - GraphConstants.NodeExtraWidth, 0), node.titleItem, itemPosition);
                if (node.inputConnectors.Count > 0)
                {
                    RenderConnector(graphics, node.inputBounds, node.inputState);
                }
                if (node.outputConnectors.Count > 0)
                {
                    RenderConnector(graphics, node.outputBounds, outputState);
                }
                if (inputConnected)
                {
                    RenderArrow(graphics, node.inputBounds, inputState);
                }
            }
            else
            {
                node.inputBounds  = Rectangle.Empty;
                node.outputBounds = Rectangle.Empty;

                var minimumItemSize = new SizeF(node.bounds.Width - GraphConstants.NodeExtraWidth, 0);
                foreach (var item in EnumerateNodeItems(node))
                {
                    RenderItem(graphics, minimumItemSize, item, itemPosition);
                    var inputConnector = item.Input;
                    if (inputConnector != null && inputConnector.Enabled)
                    {
                        if (!inputConnector.bounds.IsEmpty)
                        {
                            var state     = RenderState.None;
                            var connected = false;
                            foreach (var connection in node.connections)
                            {
                                if (connection.To == inputConnector)
                                {
                                    state    |= connection.state;
                                    connected = true;
                                }
                            }

                            RenderConnector(graphics,
                                            inputConnector.bounds,
                                            inputConnector.state);

                            if (connected)
                            {
                                RenderArrow(graphics, inputConnector.bounds, state);
                            }
                        }
                    }
                    var outputConnector = item.Output;
                    if (outputConnector != null && outputConnector.Enabled)
                    {
                        if (!outputConnector.bounds.IsEmpty)
                        {
                            var state = outputConnector.state;
                            foreach (var connection in node.connections)
                            {
                                if (connection.From == outputConnector)
                                {
                                    state |= connection.state | RenderState.Connected;
                                }
                            }
                            RenderConnector(graphics, outputConnector.bounds, state);
                        }
                    }
                    itemPosition.Y += item.bounds.Height + GraphConstants.ItemSpacing;
                }
            }
        }
Esempio n. 11
0
        private void DrawStencilItem(StencilItem stencil, DrawShapeEventArgs e)
        {
            GraphicsPath         path        = e.Path;
            RectangleF           rect        = new Rectangle();
            FlowchartStencilType stencilType = (FlowchartStencilType)Enum.Parse(typeof(FlowchartStencilType), stencil.Key);

            float width  = e.Width;
            float height = e.Height;
            float percX  = 0;
            float percY  = 0;
            float perc   = 0;
            float midX   = 0;
            float midY   = 0;

            rect.Width  = width;
            rect.Height = height;
            midX        = width / 2;
            midY        = height / 2;

            if (stencilType == FlowchartStencilType.Default)
            {
                percX = 20;
                percY = 20;

                path.AddArc(0, 0, percX, percY, 180, 90);
                path.AddArc(width - percX, 0, percX, percY, 270, 90);
                path.AddArc(width - percX, height - percY, percX, percY, 0, 90);
                path.AddArc(0, height - percY, percX, percY, 90, 90);
                path.CloseFigure();

                stencil.Redraw = true;
            }
            else if (stencilType == FlowchartStencilType.Card)
            {
                percX = width * 0.2F;
                percY = height * 0.2F;

                path.AddLine(percX, 0, width, 0);
                path.AddLine(width, 0, width, height);
                path.AddLine(width, height, 0, height);
                path.AddLine(0, height, 0, percY);
                path.CloseFigure();
            }
            else if (stencilType == FlowchartStencilType.Collate)
            {
                path.AddLine(0, 0, width, 0);
                path.AddLine(width, 0, 0, height);
                path.AddLine(0, height, width, height);
                path.AddLine(width, height, 0, 0);
            }
            else if (stencilType == FlowchartStencilType.Connector)
            {
                percX = width * 0.5F;
                percY = height * 0.5F;

                path.AddEllipse(percX, percY, width, height);
            }
            else if (stencilType == FlowchartStencilType.Data)
            {
                path.AddLine(midX / 2, 0, width, 0);
                path.AddLine(width, 0, (midX / 2) + midX, height);
                path.AddLine((midX / 2) + midX, height, 0, height);
                path.CloseFigure();
            }
            else if (stencilType == FlowchartStencilType.Decision)
            {
                path.AddLine(midX, 0, width, midY);
                path.AddLine(width, midY, midX, height);
                path.AddLine(midX, height, 0, midY);
                path.CloseFigure();
            }
            else if (stencilType == FlowchartStencilType.Delay)
            {
                percX = width * 0.2F;

                path.AddArc(percX, 0, width * 0.8F, height, 270, 180);
                path.AddLine(0, height, 0, 0);
                path.CloseFigure();
            }
            else if (stencilType == FlowchartStencilType.Display)
            {
                percX = width * 0.2F;

                path.AddArc(percX, 0, width * 0.8F, height, 270, 180);

                path.AddLine(percX, height, 0, height / 2);
                path.AddLine(0, height / 2, percX, 0);

                path.CloseFigure();
            }
            else if (stencilType == FlowchartStencilType.Direct)
            {
                percX = width * 0.3F;

                path.AddLine(width * 0.7F, height, percX, height);
                path.AddArc(0, 0, percX, height, 90, 180);
                path.AddLine(width * 0.7F, 0, percX, 0);
                path.AddArc(width * 0.7F, 0, percX, height, 270, -180);
                path.CloseFigure();

                path.StartFigure();
                path.AddEllipse(width * 0.7F, 0, percX, height);
            }
            else if (stencilType == FlowchartStencilType.Document)
            {
                PointF[] points = new PointF[4];

                points[0].X = 0;
                points[0].Y = height * 0.95F;
                points[1].X = width * 0.25F;
                points[1].Y = height;
                points[2].X = width * 0.75F;
                points[2].Y = height * 0.85F;
                points[3].X = width;
                points[3].Y = height * 0.8F;

                path.AddLine(new Point(0, 0), points[0]);
                path.AddCurve(points);
                path.AddLine(points[3], new PointF(width, 0));
                path.CloseFigure();
            }
            else if (stencilType == FlowchartStencilType.Extract)
            {
                percX = width * 0.25F;
                percY = height * 0.75F;

                path.AddLine(percX, 0, percX * 2, percY);
                path.AddLine(percX * 2, percY, 0, percY);
                path.CloseFigure();
            }
            else if (stencilType == FlowchartStencilType.InternalStorage)
            {
                perc = width * 0.15F;

                path.AddRectangle(rect);
                path.AddLine(perc, 0, perc, height);
                path.CloseFigure();

                path.AddLine(0, perc, width, perc);
                path.CloseFigure();
            }
            else if (stencilType == FlowchartStencilType.ManualInput)
            {
                percY = height * 0.25F;

                path.AddLine(0, percY, width, 0);
                path.AddLine(width, 0, width, height);
                path.AddLine(width, height, 0, height);
                path.CloseFigure();
            }
            else if (stencilType == FlowchartStencilType.ManualOperation)
            {
                percX = width * 0.2F;

                path.AddLine(0, 0, width, 0);
                path.AddLine(width, 0, width - percX, height);
                path.AddLine(width - percX, height, percX, height);

                path.CloseFigure();
            }
            else if (stencilType == FlowchartStencilType.MultiDocument)
            {
                PointF[] points = new PointF[4];

                width = width * 0.8F;

                points[0].X = 0;
                points[0].Y = height * 0.95F;
                points[1].X = width * 0.25F;
                points[1].Y = height;
                points[2].X = width * 0.75F;
                points[2].Y = height * 0.85F;
                points[3].X = width;
                points[3].Y = height * 0.8F;

                path.AddLine(new PointF(0, height * 0.2F), points[0]);
                path.AddCurve(points);
                path.AddLine(points[3], new PointF(width, height * 0.2F));
                path.CloseFigure();

                width = rect.Width;

                path.AddLine(width * 0.2F, height * 0.1F, width * 0.2F, 0);
                path.AddLine(width * 0.2F, 0, width, 0);
                path.AddLine(width, 0, width, height * 0.6F);
                path.AddLine(width, height * 0.6F, width * 0.9F, height * 0.6F);
                path.AddLine(width * 0.9F, height * 0.6F, width * 0.9F, height * 0.1F);
                path.CloseFigure();

                path.AddLine(width * 0.1F, height * 0.2F, width * 0.1F, height * 0.1F);
                path.AddLine(width * 0.1F, height * 0.1F, width * 0.9F, height * 0.1F);
                path.AddLine(width * 0.9F, height * 0.1F, width * 0.9F, height * 0.7F);
                path.AddLine(width * 0.9F, height * 0.7F, width * 0.8F, height * 0.7F);
                path.AddLine(width * 0.8F, height * 0.7F, width * 0.8F, height * 0.2F);
                path.CloseFigure();
            }
            else if (stencilType == FlowchartStencilType.OffPageConnector)
            {
                percX = width * 0.5F;
                percY = height * 0.75F;

                path.AddLine(0, 0, width, 0);
                path.AddLine(width, 0, width, percY);
                path.AddLine(width, percY, percX, height);
                path.AddLine(percX, height, 0, percY);
                path.CloseFigure();
            }
            else if (stencilType == FlowchartStencilType.PredefinedProcess)
            {
                perc = width * 0.1F;

                path.AddRectangle(rect);
                path.CloseFigure();

                path.AddLine(perc, 0, perc, height);
                path.CloseFigure();

                path.AddLine(width - perc, 0, width - perc, height);
                path.CloseFigure();
            }
            else if (stencilType == FlowchartStencilType.Preparation)
            {
                percX = width * 0.2F;

                path.AddLine(0, midY, percX, 0);
                path.AddLine(percX, 0, width - percX, 0);
                path.AddLine(width - percX, 0, width, midY);
                path.AddLine(width, midY, width - percX, height);
                path.AddLine(width - percX, height, percX, height);

                path.CloseFigure();
            }
            else if (stencilType == FlowchartStencilType.Process)
            {
                path.AddRectangle(new RectangleF(0, 0, width, height));
            }
            else if (stencilType == FlowchartStencilType.Process2)
            {
                percX = width * 0.2F;
                percY = height * 0.2F;

                if (percX < percY)
                {
                    percY = percX;
                }
                else
                {
                    percX = percY;
                }

                path.AddArc(0, 0, percX, percY, 180, 90);
                path.AddArc(width - percX, 0, percX, percY, 270, 90);
                path.AddArc(width - percX, height - percY, percX, percY, 0, 90);
                path.AddArc(0, height - percY, percX, percY, 90, 90);
                path.CloseFigure();
            }
            else if (stencilType == FlowchartStencilType.Terminator)
            {
                percX = width * 0.5F;
                percY = height * 0.20F;

                path.AddArc(0, percY, percX, percY * 2, 90, 180);
                path.AddArc(width - percX, percY, percX, percY * 2, 270, 180);
                path.CloseFigure();

                stencil.KeepAspect = true;
            }
            else if (stencilType == FlowchartStencilType.Tape)
            {
                PointF[] points       = new PointF[5];
                PointF[] pointsBottom = new PointF[5];

                points[0].X = 0;
                points[0].Y = height * 0.05F;
                points[1].X = width * 0.25F;
                points[1].Y = height * 0.1F;
                points[2].X = width * 0.5F;
                points[2].Y = height * 0.05F;
                points[3].X = width * 0.75F;
                points[3].Y = 0;
                points[4].X = width;
                points[4].Y = height * 0.05F;

                pointsBottom[4].X = 0;
                pointsBottom[4].Y = height * 0.95F;
                pointsBottom[3].X = width * 0.25F;
                pointsBottom[3].Y = height;
                pointsBottom[2].X = width * 0.5F;
                pointsBottom[2].Y = height * 0.95F;
                pointsBottom[1].X = width * 0.75F;
                pointsBottom[1].Y = height * 0.9F;
                pointsBottom[0].X = width;
                pointsBottom[0].Y = height * 0.95F;

                path.AddCurve(points);
                path.AddLine(points[4], pointsBottom[0]);

                path.AddCurve(pointsBottom);
                path.CloseFigure();
            }
            else if (stencilType == FlowchartStencilType.Junction)
            {
                percX = width * 0.25F;
                percY = height * 0.25F;

                if (percX > percY)
                {
                    perc = percX;
                }
                else
                {
                    perc = percY;
                }

                path.AddEllipse(perc, perc, perc * 2, perc * 2);
                path.CloseFigure();

                path.StartFigure();
                path.AddLine(perc * 2, perc, perc * 2, perc * 3);

                path.StartFigure();
                path.AddLine(perc, perc * 2, perc * 3, perc * 2);


                Matrix matrix = new Matrix(1, 0, 0, 1, 0, 0);

                //Rotate the matrix through 45 degress
                perc = perc * 2;
                matrix.RotateAt(45, new PointF(perc, perc));

                //Transform the graphicspath object
                path.Transform(matrix);
            }
            else if (stencilType == FlowchartStencilType.LogicalOr)
            {
                percX = width * 0.5F;
                percY = height * 0.5F;

                if (percX > percY)
                {
                    perc = percX;
                }
                else
                {
                    perc = percY;
                }

                path.AddEllipse(perc, perc, perc * 2, perc * 2);
                path.AddLine(perc * 2, perc, perc * 2, perc * 3);
                path.CloseFigure();
                path.AddLine(perc, perc * 2, perc * 3, perc * 2);
            }
            else if (stencilType == FlowchartStencilType.Sort)
            {
                percX = width * 0.5F;
                percY = height * 0.5F;

                path.AddLine(0, percY, percX, 0);
                path.AddLine(percX, 0, width, percY);

                path.AddLine(width, percY, percX, height);
                path.AddLine(percX, height, 0, percY);

                path.CloseFigure();
                path.StartFigure();

                path.AddLine(0, percY, width, percY);
            }
            else if (stencilType == FlowchartStencilType.Merge)
            {
                path.AddLine(0, 0, width, 0);
                path.AddLine(width, 0, width * 0.5F, height);
                path.CloseFigure();
            }
            else if (stencilType == FlowchartStencilType.StoredData)
            {
                percX = width * 0.3F;

                path.AddArc(0, 0, percX, height, 90, 180);
                path.AddArc(width * 0.85F, 0, percX, height, 270, -180);
                path.CloseFigure();
            }
            else if (stencilType == FlowchartStencilType.Sequential)
            {
                if (width > height)
                {
                    perc = height;
                }
                else
                {
                    perc = width;
                }

                path.AddArc(0, 0, perc, perc, 45, -315);
                path.AddLine(perc * 0.5F, perc, perc, perc);
                path.AddLine(perc, perc, perc, perc * 0.85F);
                path.CloseFigure();
            }
            else if (stencilType == FlowchartStencilType.Magnetic)
            {
                percY = height * 0.4F;

                path.AddArc(0, -height * 0.2F, width, percY, 180, -180);
                path.AddLine(width, 0, width, height * 0.8F);
                path.AddArc(0, height * 0.6F, width, percY, 0, 180);
                path.AddLine(0, height * 0.8F, 0, 0);
                //path.CloseFigure();

                //Define two shapes so that not see through
                path.StartFigure();
                path.AddLine(0, 0, width, 0);
                path.AddArc(0, -height * 0.2F, width, percY, 0, 180);
            }
        }
        /// <summary>
        /// 创建路径。
        /// </summary>
        /// <param name="rect">用来创建路径的矩形。</param>
        /// <param name="cornerStyle">圆角弯曲样式。</param>
        /// <param name="roundStyle">圆角的样式。</param>
        /// <param name="radius">圆角半径。</param>
        /// <param name="correct">是否把矩形长宽减 1,以便画出边框。</param>
        /// <returns>创建的路径。</returns>
        public static GraphicsPath CreateGraphicsPath(Rectangle rect, CornerStyle cornerStyle, RoundStyle roundStyle, float radius, bool correct)
        {
            //-----------------校准-----------------
            if (correct)
            {
                rect.Width--;
                rect.Height--;
            }

            //-----------------定义返回值-----------------
            GraphicsPath path = new GraphicsPath();

            //-----------------特殊情况处理-----------------
            if (float.IsNaN(radius) || radius <= 0f)
            {
                path.AddRectangle(rect);
                return(path);
            }
            //-----------------临时变量定义-----------------
            float  diameter       = radius * 2;                                          //直径
            float  halfWidth      = rect.Width / 2f;                                     //宽度一半
            float  halfHeight     = rect.Height / 2f;                                    //高度一半
            PointF ptMiddleCenter = new PointF(rect.X + halfWidth, rect.Y + halfHeight); //中心点
            float  lrDegrees      = 0f;                                                  //半径大于半高,圆心角
            float  lrOffset       = 0f;                                                  //半径大于半高,圆弧到边距离

            if ((roundStyle & RoundStyle.All) != 0 && radius > halfHeight)
            {
                double lrRadian = Math.Acos((radius - halfHeight) / radius); //弧度
                lrDegrees = (float)MathEx.ToDegrees(lrRadian);               //角度
                lrOffset  = (float)(radius * Math.Sin(lrRadian));
            }
            float tbDegrees = 0f; //半径大于半宽,圆心角
            float tbOffset  = 0f; //半径大于办宽,圆弧到边距离

            if ((roundStyle & RoundStyle.All) != 0 && radius > halfWidth)
            {
                double tbRadian = Math.Acos((radius - halfWidth) / radius); //弧度
                tbDegrees = (float)MathEx.ToDegrees(tbRadian);              //角度
                tbOffset  = (float)(radius * Math.Sin(tbRadian));
            }
            //临时变量
            PointF ptBegin;
            PointF ptEnd;


            #region 左上
            if ((roundStyle & RoundStyle.TopLeft) == 0)//直角
            {
                if ((cornerStyle & CornerStyle.LeftIn) != 0)
                {
                    ptBegin = new PointF(rect.X + radius, ptMiddleCenter.Y);
                    ptEnd   = new PointF(rect.X, rect.Y);
                    path.AddLine(ptBegin, ptEnd);
                }
                else if ((cornerStyle & CornerStyle.LeftOut) != 0)
                {
                    ptBegin = new PointF(rect.X, ptMiddleCenter.Y);
                    ptEnd   = new PointF(rect.X + radius, rect.Y);
                    path.AddLine(ptBegin, ptEnd);
                }
                else if ((cornerStyle & CornerStyle.TopIn) != 0)
                {
                    ptBegin = new PointF(rect.X, rect.Y);
                    ptEnd   = new PointF(ptMiddleCenter.X, rect.Y + radius);
                    path.AddLine(ptBegin, ptEnd);
                }
                else if ((cornerStyle & CornerStyle.TopOut) != 0)
                {
                    ptBegin = new PointF(rect.X, rect.Y + radius);
                    ptEnd   = new PointF(ptMiddleCenter.X, rect.Y);
                    path.AddLine(ptBegin, ptEnd);
                }
                else
                {
                    ptBegin = ptEnd = new PointF(rect.X, rect.Y);
                    path.AddLine(ptBegin, ptEnd);
                }
            }
            else//圆角
            {
                if ((cornerStyle & CornerStyle.LeftIn) != 0)
                {
                    if (radius > halfHeight)
                    {
                        path.AddArc(rect.X - radius, rect.Y, diameter, diameter, 270 + lrDegrees, -lrDegrees);
                    }
                    else
                    {
                        path.AddArc(rect.X - radius, rect.Y, diameter, diameter, 0, -90);
                    }
                }
                else if ((cornerStyle & CornerStyle.LeftOut) != 0)
                {
                    if (radius > halfHeight)
                    {
                        path.AddArc(rect.X - (radius - lrOffset), rect.Y, diameter, diameter, 270 - lrDegrees, lrDegrees);
                    }
                    else
                    {
                        path.AddArc(rect.X, rect.Y, diameter, diameter, 180, 90);
                    }
                }
                else if ((cornerStyle & CornerStyle.TopIn) != 0)
                {
                    if (radius > halfWidth)
                    {
                        path.AddArc(rect.X, rect.Y - radius, diameter, diameter, 180, -tbDegrees);
                    }
                    else
                    {
                        path.AddArc(rect.X, rect.Y - radius, diameter, diameter, 180, -90);
                    }
                }
                else if ((cornerStyle & CornerStyle.TopOut) != 0)
                {
                    if (radius > halfWidth)
                    {
                        path.AddArc(rect.X, rect.Y - (radius - tbOffset), diameter, diameter, 180, tbDegrees);
                    }
                    else
                    {
                        path.AddArc(rect.X, rect.Y, diameter, diameter, 180, 90);
                    }
                }
                else
                {
                    path.AddArc(rect.X, rect.Y, diameter, diameter, 180, 90);
                }
            }
            #endregion


            #region 右上
            if ((roundStyle & RoundStyle.TopRight) == 0)
            {
                if ((cornerStyle & CornerStyle.RightIn) != 0)
                {
                    ptBegin = new PointF(rect.Right, rect.Y);
                    ptEnd   = new PointF(rect.Right - radius, ptMiddleCenter.Y);
                    path.AddLine(ptBegin, ptEnd);
                }
                else if ((cornerStyle & CornerStyle.RightOut) != 0)
                {
                    ptBegin = new PointF(rect.Right - radius, rect.Y);
                    ptEnd   = new PointF(rect.Right, ptMiddleCenter.Y);
                    path.AddLine(ptBegin, ptEnd);
                }
                else if ((cornerStyle & CornerStyle.TopIn) != 0)
                {
                    ptBegin = new PointF(ptMiddleCenter.X, rect.Y + radius);
                    ptEnd   = new PointF(rect.Right, rect.Y);
                    path.AddLine(ptBegin, ptEnd);
                }
                else if ((cornerStyle & CornerStyle.TopOut) != 0)
                {
                    ptBegin = new PointF(ptMiddleCenter.X, rect.Y);
                    ptEnd   = new PointF(rect.Right, rect.Y + radius);
                    path.AddLine(ptBegin, ptEnd);
                }
                else//矩形
                {
                    ptBegin = ptEnd = new PointF(rect.Right, rect.Y);
                    path.AddLine(ptBegin, ptEnd);
                }
            }
            else
            {
                if ((cornerStyle & CornerStyle.RightIn) != 0)
                {
                    if (radius > halfHeight)
                    {
                        path.AddArc(rect.Right - radius, rect.Y, diameter, diameter, 270, -lrDegrees);
                    }
                    else
                    {
                        path.AddArc(rect.Right - radius, rect.Y, diameter, diameter, 270, -90);
                    }
                }
                else if ((cornerStyle & CornerStyle.RightOut) != 0)
                {
                    if (radius > halfHeight)
                    {
                        path.AddArc(rect.Right - radius - lrOffset, rect.Y, diameter, diameter, 270, lrDegrees);
                    }
                    else
                    {
                        path.AddArc(rect.Right - diameter, rect.Y, diameter, diameter, 270, 90);
                    }
                }
                else if ((cornerStyle & CornerStyle.TopIn) != 0)
                {
                    if (radius > halfWidth)
                    {
                        path.AddArc(rect.Right - diameter, rect.Y - radius, diameter, diameter, tbDegrees, -tbDegrees);
                    }
                    else
                    {
                        path.AddArc(rect.Right - diameter, rect.Y - radius, diameter, diameter, 90, -90);
                    }
                }
                else if ((cornerStyle & CornerStyle.TopOut) != 0)
                {
                    if (radius > halfWidth)
                    {
                        path.AddArc(rect.Right - diameter, rect.Y - (radius - tbOffset), diameter, diameter, 360 - tbDegrees, tbDegrees);
                    }
                    else
                    {
                        path.AddArc(rect.Right - diameter, rect.Y, diameter, diameter, 270, 90);
                    }
                }
                else
                {
                    path.AddArc(rect.Right - diameter, rect.Y, diameter, diameter, 270, 90);
                }
            }
            #endregion


            #region 右下
            if ((roundStyle & RoundStyle.BottomRight) == 0)
            {
                if ((cornerStyle & CornerStyle.RightIn) != 0)
                {
                    ptBegin = new PointF(rect.Right - radius, ptMiddleCenter.Y);
                    ptEnd   = new PointF(rect.Right, rect.Bottom);
                    path.AddLine(ptBegin, ptEnd);
                }
                else if ((cornerStyle & CornerStyle.RightOut) != 0)
                {
                    ptBegin = new PointF(rect.Right, ptMiddleCenter.Y);
                    ptEnd   = new PointF(rect.Right - radius, rect.Bottom);
                    path.AddLine(ptBegin, ptEnd);
                }
                else if ((cornerStyle & CornerStyle.BottomIn) != 0)
                {
                    ptBegin = new PointF(rect.Right, rect.Bottom);
                    ptEnd   = new PointF(ptMiddleCenter.X, rect.Bottom - radius);
                    path.AddLine(ptBegin, ptEnd);
                }
                else if ((cornerStyle & CornerStyle.BottomOut) != 0)
                {
                    ptBegin = new PointF(rect.Right, rect.Bottom - radius);
                    ptEnd   = new PointF(ptMiddleCenter.X, rect.Bottom);
                    path.AddLine(ptBegin, ptEnd);
                }
                else//矩形
                {
                    ptBegin = ptEnd = new PointF(rect.Right, rect.Bottom);
                    path.AddLine(ptBegin, ptEnd);
                }
            }
            else
            {
                if ((cornerStyle & CornerStyle.RightIn) != 0)
                {
                    if (radius > halfHeight)
                    {
                        path.AddArc(rect.Right - radius, rect.Bottom - diameter, diameter, diameter, 90 + lrDegrees, -lrDegrees);
                    }
                    else
                    {
                        path.AddArc(rect.Right - radius, rect.Bottom - diameter, diameter, diameter, 180, -90);
                    }
                }
                else if ((cornerStyle & CornerStyle.RightOut) != 0)
                {
                    if (radius > halfHeight)
                    {
                        path.AddArc(rect.Right - radius - lrOffset, rect.Bottom - diameter, diameter, diameter, 90 - lrDegrees, lrDegrees);
                    }
                    else
                    {
                        path.AddArc(rect.Right - diameter, rect.Bottom - diameter, diameter, diameter, 0, 90);
                    }
                }
                else if ((cornerStyle & CornerStyle.BottomIn) != 0)
                {
                    if (radius > halfWidth)
                    {
                        path.AddArc(rect.Right - diameter, rect.Bottom - radius, diameter, diameter, 0, -tbDegrees);
                    }
                    else
                    {
                        path.AddArc(rect.Right - diameter, rect.Bottom - radius, diameter, diameter, 0, -90);
                    }
                }
                else if ((cornerStyle & CornerStyle.BottomOut) != 0)
                {
                    if (radius > halfWidth)
                    {
                        path.AddArc(rect.Right - diameter, rect.Bottom - radius - tbOffset, diameter, diameter, 0, tbDegrees);
                    }
                    else
                    {
                        path.AddArc(rect.Right - diameter, rect.Bottom - diameter, diameter, diameter, 0, 90);
                    }
                }
                else
                {
                    path.AddArc(rect.Right - diameter, rect.Bottom - diameter, diameter, diameter, 0, 90);
                }
            }
            #endregion


            #region 左下
            if ((roundStyle & RoundStyle.BottomLeft) == 0)
            {
                if ((cornerStyle & CornerStyle.LeftIn) != 0)
                {
                    ptBegin = new PointF(rect.X, rect.Bottom);
                    ptEnd   = new PointF(rect.X + radius, ptMiddleCenter.Y);
                    path.AddLine(ptBegin, ptEnd);
                }
                else if ((cornerStyle & CornerStyle.LeftOut) != 0)
                {
                    ptBegin = new PointF(rect.X + radius, rect.Bottom);
                    ptEnd   = new PointF(rect.X, ptMiddleCenter.Y);
                    path.AddLine(ptBegin, ptEnd);
                }
                else if ((cornerStyle & CornerStyle.BottomIn) != 0)
                {
                    ptBegin = new PointF(ptMiddleCenter.X, rect.Bottom - radius);
                    ptEnd   = new PointF(rect.X, rect.Bottom);
                    path.AddLine(ptBegin, ptEnd);
                }
                else if ((cornerStyle & CornerStyle.BottomOut) != 0)
                {
                    ptBegin = new PointF(ptMiddleCenter.X, rect.Bottom);
                    ptEnd   = new PointF(rect.X, rect.Bottom - radius);
                    path.AddLine(ptBegin, ptEnd);
                }
                else
                {
                    ptBegin = ptEnd = new PointF(rect.X, rect.Bottom);
                    path.AddLine(ptBegin, ptEnd);
                }
            }
            else
            {
                if ((cornerStyle & CornerStyle.LeftIn) != 0)
                {
                    if (radius > halfHeight)
                    {
                        path.AddArc(rect.X - radius, rect.Bottom - diameter, diameter, diameter, 90, -lrDegrees);
                    }
                    else
                    {
                        path.AddArc(rect.X - radius, rect.Bottom - diameter, diameter, diameter, 90, -90);
                    }
                }
                else if ((cornerStyle & CornerStyle.LeftOut) != 0)
                {
                    if (radius > halfHeight)
                    {
                        path.AddArc(rect.X - (radius - lrOffset), rect.Bottom - diameter, diameter, diameter, 90, lrDegrees);
                    }
                    else
                    {
                        path.AddArc(rect.X, rect.Bottom - diameter, diameter, diameter, 90, 90);
                    }
                }
                else if ((cornerStyle & CornerStyle.BottomIn) != 0)
                {
                    if (radius > halfWidth)
                    {
                        path.AddArc(rect.X, rect.Bottom - radius, diameter, diameter, 180 + tbDegrees, -tbDegrees);
                    }
                    else
                    {
                        path.AddArc(rect.X, rect.Bottom - radius, diameter, diameter, 270, -90);
                    }
                }
                else if ((cornerStyle & CornerStyle.BottomOut) != 0)
                {
                    if (radius > halfWidth)
                    {
                        path.AddArc(rect.X, rect.Bottom - radius - tbOffset, diameter, diameter, 180 - tbDegrees, tbDegrees);
                    }
                    else
                    {
                        path.AddArc(rect.X, rect.Bottom - diameter, diameter, diameter, 90, 90);
                    }
                }
                else
                {
                    path.AddArc(rect.X, rect.Bottom - diameter, diameter, diameter, 90, 90);
                }
            }
            #endregion


            //闭合返回
            path.CloseFigure();
            return(path);
        }
Esempio n. 13
0
 public GraphicsPath RoundRect(Rectangle Rectangle, int Curve)
 {
     GraphicsPath P = new GraphicsPath();
     int ArcRectangleWidth = Curve * 2;
     P.AddArc(new Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90);
     P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90);
     P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90);
     P.AddArc(new Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90);
     P.AddLine(new Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), new Point(Rectangle.X, Curve + Rectangle.Y));
     return P;
 }
Esempio n. 14
0
        public void OnLoad(EventArgs e)
        {
            Bitmap   bmp = new Bitmap(this.Height * 0x06, this.Height * 0x02);
            Graphics g   = Graphics.FromImage(bmp);

            g.CompositingQuality = CompositingQuality.HighQuality;
            g.PixelOffsetMode    = PixelOffsetMode.HighQuality;
            g.SmoothingMode      = SmoothingMode.HighQuality;
            g.InterpolationMode  = InterpolationMode.HighQualityBicubic;

            float w      = 6.0f * this.Height;
            int   hInt   = this.Height;
            float h      = (float)hInt;
            float margin = h / 48.0f;
            float m2     = 2.0f * margin;
            float r      = h / 36.0f;     ///36.0f
            float r2     = 2.0f * r;
            float h_2    = 0.5f * h;
            float Ro     = h_2 - margin;
            float alpha  = (float)(180.0d / Math.PI * Math.Acos(1.0d - 0.5d * r / Ro));
            float beta   = (float)(180.0d / Math.PI * Math.Acos(1.0d - r / Ro));
            float betaY  = (float)Math.Sqrt(Ro * Ro - (Ro - r) * (Ro - r));
            float sqrtR2 = (float)(Math.Sqrt(0.5d) * (h - m2 - r2));
            float __R2   = h_2 - margin - r;

            __R2 *= __R2;
            for (int l = 0x00; l < 0x02; l++)
            {
                using (GraphicsPath gpNocturne = new GraphicsPath()) {
                    //left wing
                    gpNocturne.AddArc(0.5f * w - h + m2, margin, h - m2, h - m2, 180.0f + alpha, 360.0f - 2.0f * alpha);
                    gpNocturne.AddArc(0.5f * w + 2.0f * (m2 - h) + r, margin, h - m2, h - m2, alpha, 90.0f - alpha);
                    gpNocturne.AddLine(0.5f * w + 1.5f * m2 + r - 1.5f * h, h - margin, h_2, h - margin);
                    gpNocturne.AddArc(margin, margin, h - m2, h - m2, 90.0f, 90.0f - beta);
                    gpNocturne.AddLine(margin + r, h_2 + betaY, margin + r, h - margin);
                    gpNocturne.AddLine(margin + r, h - margin, margin, h - margin);
                    gpNocturne.AddLine(margin, h - margin, margin, margin);
                    gpNocturne.AddLine(margin, margin, margin + r, margin);
                    gpNocturne.AddLine(margin + r, margin, margin + r, h_2 - betaY);
                    gpNocturne.AddArc(margin, margin, h - m2, h - m2, 180.0f + beta, 90.0f - beta);
                    gpNocturne.AddLine(h_2, margin, 0.5f * w + 1.5f * m2 + r - 1.5f * h, margin);
                    gpNocturne.AddArc(0.5f * w + 2.0f * (m2 - h) + r, margin, h - m2, h - m2, 270.0f, 90.0f - alpha);
                    gpNocturne.CloseFigure();
                    //right wing
                    gpNocturne.AddArc(0.5f * w, margin, h - m2, h - m2, 360.0f - alpha, 2.0f * alpha - 360.0f);
                    gpNocturne.AddArc(0.5f * w + h - m2 - r, margin, h - m2, h - m2, 180.0f - alpha, alpha - 90.0f);
                    gpNocturne.AddLine(0.5f * w + 2.0f * (h - m2) - r, h - margin, w - h_2, h - margin);
                    gpNocturne.AddArc(w - h + margin, margin, h - m2, h - m2, 90.0f, beta - 90.0f);
                    gpNocturne.AddLine(w - margin - r, h_2 + betaY, w - margin - r, h - margin);
                    gpNocturne.AddLine(w - margin - r, h - margin, w - margin, h - margin);
                    gpNocturne.AddLine(w - margin, h - margin, w - margin, margin);
                    gpNocturne.AddLine(w - margin, margin, w - margin - r, margin);
                    gpNocturne.AddLine(w - margin - r, margin, w - margin - r, h_2 - betaY);
                    gpNocturne.AddArc(w - h + margin, margin, h - m2, h - m2, -beta, beta - 90.0f);
                    gpNocturne.AddLine(w - h_2, margin, 0.5f * w + 2.0f * (h - m2) - r, margin);
                    gpNocturne.AddArc(0.5f * w + h - m2 - r, margin, h - m2, h - m2, 270.0f, alpha - 90.0f);
                    gpNocturne.CloseFigure();
                    if (l == 0x00)
                    {
                        g.FillPath(EgyptInformation.Brushes.EgyptNocturne, gpNocturne);
                    }
                    else
                    {
                        g.FillPath(EgyptInformation.Brushes.EgyptPaintBlue, gpNocturne);
                    }
                    //g.FillPath(new SolidBrush(Color.FromArgb(0x4c,0x41,0x0b)),gpNocturne);
                    using (GraphicsPath gpGold = new GraphicsPath()) {
                        gpGold.AddPath(gpNocturne, false);
                        //left inner
                        gpGold.AddArc(margin + r, margin + r, h - m2 - r2, h - m2 - r2, 90.0f, 180.0f);
                        gpGold.AddArc(0.5f * w + 2.0f * (m2 - h) + r2, margin + r, h - m2 - r2, h - m2 - r2, 270.0f, 180.0f);
                        gpGold.CloseFigure();
                        //left ellipse
                        gpGold.AddEllipse(0.5f * w - h + m2 + r, margin + r, h - m2 - r2, h - m2 - r2);
                        gpGold.CloseFigure();
                        //right inner
                        gpGold.AddArc(w - h + margin + r, margin + r, h - m2 - r2, h - m2 - r2, 90.0f, -180.0f);
                        gpGold.AddArc(0.5f * w + h - m2, margin + r, h - m2 - r2, h - m2 - r2, 270.0f, -180.0f);
                        gpGold.CloseFigure();
                        //right ellipse
                        gpGold.AddEllipse(0.5f * w + r, margin + r, h - m2 - r2, h - m2 - r2);
                        gpGold.CloseFigure();
                        g.FillPath(EgyptInformation.Brushes.EgyptGold, gpGold);
                        GraphicsUtils.DrawGlass(g, gpGold);
                    }
                    Matrix M = new Matrix();
                    M.Scale(sqrtR2, sqrtR2);
                    RectangleF   bounds;
                    Matrix       Mtrans   = new Matrix();
                    GraphicsPath gpHedjet = EgyptInformation.GraphicsPaths.Hedjet();
                    gpHedjet.Transform(M);
                    bounds = gpHedjet.GetBounds();
                    Mtrans.Translate(-0.5f * bounds.Width, 0.0f);
                    Mtrans.Scale(-1.0f, 1.0f, MatrixOrder.Append);
                    Mtrans.Translate(0.5f * (w - h + m2), h_2 - 0.5f * bounds.Height, MatrixOrder.Append);
                    gpHedjet.Transform(Mtrans);
                    g.FillPath(EgyptInformation.Brushes.EgyptPaintWhite, gpHedjet);
                    GraphicsUtils.DrawGlass(g, gpHedjet);
                    GraphicsPath gpDeshret = EgyptInformation.GraphicsPaths.Deshret();
                    gpDeshret.Transform(M);
                    bounds = gpDeshret.GetBounds();
                    Mtrans.Reset();
                    Mtrans.Translate(0.5f * (w + h - m2 - bounds.Width), h_2 - 0.5f * bounds.Height);
                    gpDeshret.Transform(Mtrans);
                    g.FillPath(EgyptInformation.Brushes.EgyptPaintRed, gpDeshret);
                    GraphicsUtils.DrawGlass(g, gpDeshret);
                }
                g.TranslateTransform(0.0f, h);
            }
            BitmapData bmd = bmp.LockBits(new Rectangle(0x00, 0x00, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            this.texturePointer = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2D, this.texturePointer);
            GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (float)TextureEnvMode.Modulate);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (float)TextureMinFilter.LinearMipmapLinear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (float)TextureMagFilter.Linear);
            Glu.Glu.Build2DMipmap(Glu.TextureTarget.Texture2D, (int)PixelInternalFormat.Four, bmp.Width, bmp.Height, OpenTK.Graphics.PixelFormat.Bgra, Glu.PixelType.UnsignedByte, bmd.Scan0);
            bmp.UnlockBits(bmd);
        }
Esempio n. 15
0
        protected virtual void DrawRow(PaintEventArgs e, ref DrawContext context, int row, Rectangle rowRect)
        {
            TreeNodeAdv node = RowMap[row];

            context.DrawSelection      = DrawSelectionMode.None;
            context.CurrentEditorOwner = _currentEditorOwner;
            if (DragMode)
            {
                if ((_dropPosition.Node == node) && _dropPosition.Position == NodePosition.Inside && HighlightDropPosition)
                {
                    context.DrawSelection = DrawSelectionMode.Active;
                }
            }
            else
            {
                if (node.IsSelected && Focused)
                {
                    context.DrawSelection = DrawSelectionMode.Active;
                }
                else if (node.IsSelected && !Focused && !HideSelection)
                {
                    context.DrawSelection = DrawSelectionMode.Inactive;
                }
            }
            context.DrawFocus = Focused && CurrentNode == node;

            // custom draw by mikel
            Rectangle focusRect = new Rectangle(OffsetX, rowRect.Y, DisplayRectangle.Width, rowRect.Height);

            context.Bounds = focusRect;
            OnBeforeNodeDrawing(node, context);

            if (FullRowSelect)
            {
                context.DrawFocus = false;
                if (context.DrawSelection == DrawSelectionMode.Active || context.DrawSelection == DrawSelectionMode.Inactive)
                {
                    // Handle high contrast mode separately.
                    if (SystemInformation.HighContrast)
                    {
                        // ml: use the highlight color of the system scheme in high contrast mode.
                        using (SolidBrush brush = new SolidBrush(SystemColors.Highlight))
                            e.Graphics.FillRectangle(brush, focusRect);
                    }
                    else
                    {
                        RectangleF bounds = focusRect;
                        bounds.X     += 1.5f;
                        bounds.Y     -= 0.5f;
                        bounds.Width -= 2;
                        bounds.Height--;

                        float        cornerSize = 5;
                        GraphicsPath fillPath   = new GraphicsPath();
                        if (isWin8OrAbove)
                        {
                            fillPath.AddRectangle(bounds);
                        }
                        else
                        {
                            fillPath.AddArc(bounds.Left, bounds.Top, cornerSize, cornerSize, 180, 90);
                            fillPath.AddArc(bounds.Right - cornerSize, bounds.Top, cornerSize, cornerSize, -90, 90);
                            fillPath.AddArc(bounds.Right - cornerSize, bounds.Bottom - cornerSize, cornerSize, cornerSize, 0, 90);
                            fillPath.AddArc(bounds.Left, bounds.Bottom - cornerSize, cornerSize, cornerSize, 90, 90);
                            fillPath.CloseAllFigures();
                        }

                        GraphicsPath outlinePath = new GraphicsPath();
                        bounds.X -= 0.5f;
                        bounds.Y += 0.5f;
                        if (isWin8OrAbove)
                        {
                            outlinePath.AddRectangle(bounds);
                        }
                        else
                        {
                            outlinePath.AddArc(bounds.Left, bounds.Top, cornerSize, cornerSize, 180, 90);
                            outlinePath.AddArc(bounds.Right - cornerSize, bounds.Top, cornerSize, cornerSize, -90, 90);
                            outlinePath.AddArc(bounds.Right - cornerSize, bounds.Bottom - cornerSize, cornerSize, cornerSize, 0, 90);
                            outlinePath.AddArc(bounds.Left, bounds.Bottom - cornerSize, cornerSize, cornerSize, 90, 90);
                            outlinePath.CloseAllFigures();
                        }

                        if (context.DrawSelection == DrawSelectionMode.Active)
                        {
                            if (isWin8OrAbove)
                            {
                                using (SolidBrush brush = new SolidBrush(Color.FromArgb(0xFF, 0xD1, 0xE8, 0xFF)))
                                    e.Graphics.FillPath(brush, fillPath);
                                using (Pen pen = new Pen(Color.FromArgb(255, 0x6E, 0xC0, 0xE7)))
                                    e.Graphics.DrawPath(pen, outlinePath);
                            }
                            else
                            {
                                using (LinearGradientBrush gradientBrush = new LinearGradientBrush(
                                           new PointF(0, bounds.Top),
                                           new PointF(0, bounds.Bottom),
                                           Color.FromArgb(255, 0xF1, 0xF7, 0xFE),
                                           Color.FromArgb(255, 0xCF, 0xE4, 0xFE)))
                                    e.Graphics.FillPath(gradientBrush, fillPath);

                                using (Pen pen = new Pen(Color.FromArgb(255, 0x83, 0xAC, 0xDD)))
                                    e.Graphics.DrawPath(pen, outlinePath);
                            }

                            context.DrawSelection = DrawSelectionMode.FullRowSelect;
                        }
                        else
                        {
                            if (isWin8OrAbove)
                            {
                                using (SolidBrush brush = new SolidBrush(Color.FromArgb(0xFF, 0xF7, 0xF7, 0xF7)))
                                    e.Graphics.FillPath(brush, fillPath);
                                using (Pen pen = new Pen(Color.FromArgb(0xFF, 0xDE, 0xDE, 0xDE)))
                                    e.Graphics.DrawPath(pen, outlinePath);
                            }
                            else
                            {
                                using (LinearGradientBrush gradientBrush = new LinearGradientBrush(
                                           new PointF(0, bounds.Top),
                                           new PointF(0, bounds.Bottom),
                                           Color.FromArgb(255, 0xF8, 0xF8, 0xF8),
                                           Color.FromArgb(255, 0xE5, 0xE5, 0xE5)))
                                    e.Graphics.FillPath(gradientBrush, fillPath);

                                using (Pen pen = new Pen(Color.FromArgb(255, 0xD9, 0xD9, 0xD9)))
                                    e.Graphics.DrawPath(pen, outlinePath);
                            }

                            context.DrawSelection = DrawSelectionMode.None;
                        }
                    }
                }
            }

            // by mikez, mikel
            if ((GridLineStyle & GridLineStyle.Horizontal) == GridLineStyle.Horizontal)
            {
                e.Graphics.DrawLine(_gridPen, 0, rowRect.Bottom, e.Graphics.ClipBounds.Right, rowRect.Bottom);
            }

            if (ShowLines)
            {
                DrawLines(e.Graphics, node, rowRect);
            }

            DrawNode(node, context);

            // ml: added for overlay images.
            OnAfterNodeDrawing(node, context);
        }
        /// <summary>This method will paint the control.</summary>
        /// <param name="g">The paint event graphics object.</param>
        private void PaintBack(Graphics g)
        {
            //Set Graphics smoothing mode to Anit-Alias--
            g.SmoothingMode = SmoothingMode.AntiAlias;
            //-------------------------------------------

            //Declare Variables------------------
            int                 ArcWidth                = RoundCorners * 2;
            int                 ArcHeight               = RoundCorners * 2;
            int                 ArcX1                   = 0;
            int                 ArcX2                   = (ShadowControl) ? (Width - (ArcWidth + 1)) - ShadowThickness : Width - (ArcWidth + 1);
            int                 ArcY1                   = 10;
            int                 ArcY2                   = (ShadowControl) ? (Height - (ArcHeight + 1)) - ShadowThickness : Height - (ArcHeight + 1);
            GraphicsPath        path                    = new GraphicsPath();
            Brush               BorderBrush             = new SolidBrush(BorderColor);
            Pen                 BorderPen               = new Pen(BorderBrush, BorderThickness);
            LinearGradientBrush BackgroundGradientBrush = null;
            Brush               BackgroundBrush         = new SolidBrush(BackgroundColor);
            SolidBrush          ShadowBrush             = null;
            GraphicsPath        ShadowPath              = null;

            //-----------------------------------

            //Check if shadow is needed----------
            if (ShadowControl)
            {
                ShadowBrush = new SolidBrush(ShadowColor);
                ShadowPath  = new GraphicsPath();
                ShadowPath.AddArc(ArcX1 + ShadowThickness, ArcY1 + ShadowThickness, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // TopCount Left
                ShadowPath.AddArc(ArcX2 + ShadowThickness, ArcY1 + ShadowThickness, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //TopCount Right
                ShadowPath.AddArc(ArcX2 + ShadowThickness, ArcY2 + ShadowThickness, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right
                ShadowPath.AddArc(ArcX1 + ShadowThickness, ArcY2 + ShadowThickness, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle);  //Bottom Left
                ShadowPath.CloseAllFigures();

                //Paint Rounded Rectangle------------
                g.FillPath(ShadowBrush, ShadowPath);
                //-----------------------------------
            }
            //-----------------------------------

            //Create Rounded Rectangle Path------
            path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // TopCount Left
            path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //TopCount Right
            path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right
            path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle);  //Bottom Left
            path.CloseAllFigures();
            //-----------------------------------

            //Check if Gradient Mode is enabled--
            if (BackgroundGradientMode == GroupBoxGradientMode.None)
            {
                //Paint Rounded Rectangle------------
                g.FillPath(BackgroundBrush, path);
                //-----------------------------------
            }
            else
            {
                BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, Width, Height), BackgroundColor, BackgroundGradientColor, (LinearGradientMode)BackgroundGradientMode);

                //Paint Rounded Rectangle------------
                g.FillPath(BackgroundGradientBrush, path);
                //-----------------------------------
            }
            //-----------------------------------

            //Paint Borded-----------------------
            g.DrawPath(BorderPen, path);
            //-----------------------------------

            //Destroy Graphic Objects------------
            if (path != null)
            {
                path.Dispose();
            }
            if (BorderBrush != null)
            {
                BorderBrush.Dispose();
            }
            if (BorderPen != null)
            {
                BorderPen.Dispose();
            }
            if (BackgroundGradientBrush != null)
            {
                BackgroundGradientBrush.Dispose();
            }
            if (BackgroundBrush != null)
            {
                BackgroundBrush.Dispose();
            }
            if (ShadowBrush != null)
            {
                ShadowBrush.Dispose();
            }
            if (ShadowPath != null)
            {
                ShadowPath.Dispose();
            }
            //-----------------------------------
        }
        /// <summary>This method will paint the group title.</summary>
        /// <param name="g">The paint event graphics object.</param>
        private void PaintGroupText(Graphics g)
        {
            //Check if string has something-------------
            if (GroupTitle == string.Empty)
            {
                return;
            }
            //------------------------------------------

            //Set Graphics smoothing mode to Anit-Alias--
            g.SmoothingMode = SmoothingMode.AntiAlias;
            //-------------------------------------------

            //Declare Variables------------------
            SizeF StringSize  = g.MeasureString(GroupTitle, Font);
            Size  StringSize2 = StringSize.ToSize();

            if (GroupImage != null)
            {
                StringSize2.Width += 18;
            }
            int                 ArcWidth                = RoundCorners;
            int                 ArcHeight               = RoundCorners;
            int                 ArcX1                   = 20;
            int                 ArcX2                   = (StringSize2.Width + 34) - (ArcWidth + 1);
            int                 ArcY1                   = 0;
            int                 ArcY2                   = 24 - (ArcHeight + 1);
            GraphicsPath        path                    = new GraphicsPath();
            Brush               BorderBrush             = new SolidBrush(BorderColor);
            Pen                 BorderPen               = new Pen(BorderBrush, BorderThickness);
            LinearGradientBrush BackgroundGradientBrush = null;
            Brush               BackgroundBrush         = (PaintGroupBox) ? new SolidBrush(CustomGroupBoxColor) : new SolidBrush(BackgroundColor);
            SolidBrush          TextColorBrush          = new SolidBrush(ForeColor);
            SolidBrush          ShadowBrush             = null;
            GraphicsPath        ShadowPath              = null;

            //-----------------------------------

            //Check if shadow is needed----------
            if (ShadowControl)
            {
                ShadowBrush = new SolidBrush(ShadowColor);
                ShadowPath  = new GraphicsPath();
                ShadowPath.AddArc(ArcX1 + (ShadowThickness - 1), ArcY1 + (ShadowThickness - 1), ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // TopCount Left
                ShadowPath.AddArc(ArcX2 + (ShadowThickness - 1), ArcY1 + (ShadowThickness - 1), ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //TopCount Right
                ShadowPath.AddArc(ArcX2 + (ShadowThickness - 1), ArcY2 + (ShadowThickness - 1), ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right
                ShadowPath.AddArc(ArcX1 + (ShadowThickness - 1), ArcY2 + (ShadowThickness - 1), ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle);  //Bottom Left
                ShadowPath.CloseAllFigures();

                //Paint Rounded Rectangle------------
                g.FillPath(ShadowBrush, ShadowPath);
                //-----------------------------------
            }
            //-----------------------------------

            //Create Rounded Rectangle Path------
            path.AddArc(ArcX1, ArcY1, ArcWidth, ArcHeight, 180, GroupBoxConstants.SweepAngle); // TopCount Left
            path.AddArc(ArcX2, ArcY1, ArcWidth, ArcHeight, 270, GroupBoxConstants.SweepAngle); //TopCount Right
            path.AddArc(ArcX2, ArcY2, ArcWidth, ArcHeight, 360, GroupBoxConstants.SweepAngle); //Bottom Right
            path.AddArc(ArcX1, ArcY2, ArcWidth, ArcHeight, 90, GroupBoxConstants.SweepAngle);  //Bottom Left
            path.CloseAllFigures();
            //-----------------------------------

            //Check if Gradient Mode is enabled--
            if (PaintGroupBox)
            {
                //Paint Rounded Rectangle------------
                g.FillPath(BackgroundBrush, path);
                //-----------------------------------
            }
            else
            {
                if (BackgroundGradientMode == GroupBoxGradientMode.None)
                {
                    //Paint Rounded Rectangle------------
                    g.FillPath(BackgroundBrush, path);
                    //-----------------------------------
                }
                else
                {
                    BackgroundGradientBrush = new LinearGradientBrush(new Rectangle(0, 0, Width, Height), BackgroundColor, BackgroundGradientColor, (LinearGradientMode)BackgroundGradientMode);

                    //Paint Rounded Rectangle------------
                    g.FillPath(BackgroundGradientBrush, path);
                    //-----------------------------------
                }
            }
            //-----------------------------------

            //Paint Borded-----------------------
            g.DrawPath(BorderPen, path);
            //-----------------------------------

            //Paint Text-------------------------
            int CustomStringWidth = (GroupImage != null) ? 44 : 28;

            g.DrawString(GroupTitle, Font, TextColorBrush, CustomStringWidth, 5);
            //-----------------------------------

            //Draw GroupImage if there is one----
            if (GroupImage != null)
            {
                g.DrawImage(GroupImage, 28, 4, 16, 16);
            }
            //-----------------------------------

            //Destroy Graphic Objects------------
            if (path != null)
            {
                path.Dispose();
            }
            if (BorderBrush != null)
            {
                BorderBrush.Dispose();
            }
            if (BorderPen != null)
            {
                BorderPen.Dispose();
            }
            if (BackgroundGradientBrush != null)
            {
                BackgroundGradientBrush.Dispose();
            }
            if (BackgroundBrush != null)
            {
                BackgroundBrush.Dispose();
            }
            if (TextColorBrush != null)
            {
                TextColorBrush.Dispose();
            }
            if (ShadowBrush != null)
            {
                ShadowBrush.Dispose();
            }
            if (ShadowPath != null)
            {
                ShadowPath.Dispose();
            }

            //-----------------------------------
        }
Esempio n. 18
0
        protected override void OnPaint(PaintEventArgs e)
        {
            #region Transparency
            if (transparency && Parent != null)
            {
                Bitmap behind = new Bitmap(Parent.Width, Parent.Height);
                foreach (Control c in Parent.Controls)
                {
                    if (c.Bounds.IntersectsWith(this.Bounds) & c != this)
                    {
                        c.DrawToBitmap(behind, c.Bounds);
                    }
                }
                e.Graphics.DrawImage(behind, -Left, -Top);
                behind.Dispose();
            }
            #endregion
            #region DrawCircle
            float angle = (value * 360.0f / maxValue);

            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;

            RectangleF outerRect = new RectangleF(0, 0, outerRadius * 2, outerRadius * 2);
            RectangleF innerRect = new RectangleF(outerRadius - innerRadius,
                                                  outerRadius - innerRadius, innerRadius * 2, innerRadius * 2);
            using (GraphicsPath progPath = new GraphicsPath())
            {
                progPath.AddArc(outerRect, angle - 90, -angle);
                if (allowText)
                {
                    progPath.AddArc(innerRect, -90, angle);
                }
                else
                {
                    progPath.AddLine(new Point(outerRadius, 0), new Point(outerRadius, outerRadius));
                }
                progPath.CloseFigure();
                e.Graphics.FillPath(brush, progPath);
            }


            #endregion
            #region DrawString
            if (!allowText)
            {
                return;
            }
            string text = "%" + (value * 100.0 / maxValue).ToString("0");
            Size   textSize;
            float  ratio = 1.0f;
            if (automaticFontCalculation)
            {
                string fullPercText = "%100";
                Size   temp         = TextRenderer.MeasureText(fullPercText, this.Font);
                float  properWidth  = innerRadius * 1.2f;
                ratio = properWidth / temp.Width;
            }
            Font font = new Font(Font.Name, Font.Height * ratio);
            textSize = TextRenderer.MeasureText(text, font);
            float x = (2 * outerRadius - textSize.Width) / 2f;
            float y = (2 * outerRadius - textSize.Height) / 2f;
            using (SolidBrush textBrush = new SolidBrush(ForeColor))
                e.Graphics.DrawString(text, font, textBrush, x + 1, y);
            #endregion
        }
Esempio n. 19
0
        private void Button_Paint(object sender, PaintEventArgs e)
        {
            int totalPixels;
            int totalPercentage;
            List <Rectangle> cells;
            GraphicsPath     gp;

            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
            Rectangle r       = e.ClipRectangle;
            float     minR    = r.Width > r.Height ? r.Height / 2 : r.Width / 2;
            Brush     BackPen = new SolidBrush(this.currentColor);
            Brush     TextPen = new SolidBrush(Color.Black);

            gp = new GraphicsPath();
            try
            {
                gp.StartFigure();
                gp.AddArc(r.Left, r.Top, 2 * minR, 2 * minR, 270, -180);
                gp.AddLine(r.Left + minR, r.Bottom, r.Left + minR, r.Top);
                gp.CloseFigure();
            }
            catch { }
            try
            {
                gp.StartFigure();
                gp.AddArc(r.Right - 2 * minR - 1, r.Top, 2 * minR, 2 * minR, 270, 180);
                gp.AddLine(r.Right - minR - 1, r.Bottom, r.Right - minR - 1, r.Top);
                gp.CloseFigure();
            }
            catch { }
            if (this.fillStyle == ButtonFillStyle.Filled)
            {
                this.strfmt.Alignment     = StringAlignment.Far;
                this.strfmt.LineAlignment = StringAlignment.Far;
                try
                {
                    gp.StartFigure();
                    gp.AddLine(r.Left + minR, r.Bottom, r.Left + minR, r.Top);
                    gp.AddLine(r.Left + minR, r.Top, r.Right - minR - 1, r.Top);
                    gp.AddLine(r.Right - minR - 1, r.Bottom, r.Right - minR - 1, r.Top);
                    gp.AddLine(r.Right - minR - 1, r.Bottom, r.Left + minR, r.Bottom);
                    gp.CloseFigure();
                    e.Graphics.FillPath(BackPen, gp);
                    gp = new GraphicsPath();
                    e.Graphics.DrawString(this.label, this.Font, TextPen, new Rectangle((int)r.Left + (int)minR, (int)r.Top, (int)r.Width - 1 - 2 * (int)minR, (int)r.Height - 1), this.strfmt);
                }
                catch { }
                e.Graphics.FillPath(BackPen, gp);
            }
            else if (this.fillStyle == ButtonFillStyle.FilledColumns)
            {
                strfmt.Alignment = StringAlignment.Near;
                try
                {
                    totalPixels     = (int)r.Width - 7 - 2 * (int)minR;
                    totalPercentage = 0;
                    foreach (ColumnData d in this.columns)
                    {
                        totalPercentage += d.WidthPercent;
                    }
                    totalPixels -= (this.columns.Count - 1) * 3;
                    cells        = new List <Rectangle>();
                    foreach (ColumnData d in this.columns)
                    {
                        cells.Add(new Rectangle(cells.Count == 0 ? (int)minR + 3 : cells[cells.Count - 1].Right + 3, 0, d.WidthPercent * totalPixels / totalPercentage, r.Height));
                    }
                    gp.AddRectangles(cells.ToArray());
                    e.Graphics.FillPath(BackPen, gp);
                    gp = new GraphicsPath();
                    for (int i = 0; i < this.columns.Count; i++)
                    {
                        e.Graphics.DrawString(this.columns[i].Label, this.Font, TextPen, cells[i], this.strfmt);
                    }
                }
                catch { }
                e.Graphics.FillPath(BackPen, gp);
            }
            else if (this.fillStyle == ButtonFillStyle.UnfilledColumns)
            {
                strfmt.Alignment     = StringAlignment.Near;
                strfmt.LineAlignment = StringAlignment.Center;
                try
                {
                    totalPixels     = (int)r.Width - 7 - 2 * (int)minR;
                    totalPercentage = 0;
                    foreach (ColumnData d in this.columns)
                    {
                        totalPercentage += d.WidthPercent;
                    }
                    totalPixels -= (this.columns.Count - 1) * 3;
                    cells        = new List <Rectangle>();
                    foreach (ColumnData d in this.columns)
                    {
                        cells.Add(new Rectangle(cells.Count == 0 ? (int)minR + 3 : cells[cells.Count - 1].Right + 3, 0, d.WidthPercent * totalPixels / totalPercentage, r.Height));
                    }
                    // gp.AddRectangles(cells.ToArray());
                    e.Graphics.FillPath(BackPen, gp);
                    gp = new GraphicsPath();
                    for (int i = 0; i < this.columns.Count; i++)
                    {
                        e.Graphics.DrawString(this.columns[i].Label, this.Font, BackPen, cells[i], this.strfmt);
                    }
                }
                catch { }
                e.Graphics.FillPath(BackPen, gp);
            }
        }
        public static GraphicsPath CreatePath(Rectangle rect, int radius, ERoundStyle style, bool correction)
        {
            GraphicsPath path = new GraphicsPath();
            int          num  = correction ? 1 : 0;

            switch (style)
            {
            case ERoundStyle.None:
                path.AddRectangle(rect);
                break;

            case ERoundStyle.TopLeft:
                path.AddArc(rect.X, rect.Y, radius, radius, 180f, 90f);
                path.AddLine(rect.Right - num, rect.Y, rect.Right - num, rect.Bottom - num);
                path.AddLine(rect.Right - num, rect.Bottom - num, rect.X, rect.Bottom - num);
                break;

            case ERoundStyle.TopRight:
                path.AddArc((rect.Right - radius) - num, rect.Y, radius, radius, 270f, 90f);
                path.AddLine(rect.Right - num, rect.Bottom - num, rect.X, rect.Bottom - num);
                path.AddLine(rect.X, rect.Bottom - num, rect.X, rect.Y);
                break;

            case ERoundStyle.Top:
                path.AddArc(rect.X, rect.Y, radius, radius, 180f, 90f);
                path.AddArc((rect.Right - radius) - num, rect.Y, radius, radius, 270f, 90f);
                path.AddLine(rect.Right - num, rect.Bottom - num, rect.X, rect.Bottom - num);
                break;

            case ERoundStyle.BottomLeft:
                path.AddArc(rect.X, (rect.Bottom - radius) - num, radius, radius, 90f, 90f);
                path.AddLine(rect.X, rect.Y, rect.Right - num, rect.Y);
                path.AddLine(rect.Right - num, rect.Y, rect.Right - num, rect.Bottom - num);
                break;

            case ERoundStyle.Left:
                path.AddArc(rect.X, rect.Y, radius, radius, 180f, 90f);
                path.AddLine(rect.Right - num, rect.Y, rect.Right - num, rect.Bottom - num);
                path.AddArc(rect.X, (rect.Bottom - radius) - num, radius, radius, 90f, 90f);
                break;

            case ERoundStyle.BottomRight:
                path.AddArc((rect.Right - radius) - num, (rect.Bottom - radius) - num, radius, radius, 0f, 90f);
                path.AddLine(rect.X, rect.Bottom - num, rect.X, rect.Y);
                path.AddLine(rect.X, rect.Y, rect.Right - num, rect.Y);
                break;

            case ERoundStyle.Right:
                path.AddArc((rect.Right - radius) - num, rect.Y, radius, radius, 270f, 90f);
                path.AddArc((rect.Right - radius) - num, (rect.Bottom - radius) - num, radius, radius, 0f, 90f);
                path.AddLine(rect.X, rect.Bottom - num, rect.X, rect.Y);
                break;

            case ERoundStyle.Bottom:
                path.AddArc((rect.Right - radius) - num, (rect.Bottom - radius) - num, radius, radius, 0f, 90f);
                path.AddArc(rect.X, (rect.Bottom - radius) - num, radius, radius, 90f, 90f);
                path.AddLine(rect.X, rect.Y, rect.Right - num, rect.Y);
                break;

            case ERoundStyle.All:
                path.AddArc(rect.X, rect.Y, radius, radius, 180f, 90f);
                path.AddArc((rect.Right - radius) - num, rect.Y, radius, radius, 270f, 90f);
                path.AddArc((rect.Right - radius) - num, (rect.Bottom - radius) - num, radius, radius, 0f, 90f);
                path.AddArc(rect.X, (rect.Bottom - radius) - num, radius, radius, 90f, 90f);
                break;
            }
            path.CloseFigure();
            return(path);
        }
Esempio n. 21
0
        /// <summary>
        /// Creates the graphic path used for drawing the border
        /// </summary>
        protected virtual void InitializeGraphicPath()
        {
            if (null != graphicPath)
            {
                graphicPath.Dispose();
                graphicPath = null;
            }

            if (null != regionPath)
            {
                regionPath.Dispose();
                regionPath = null;
            }

            graphicPath = new GraphicsPath();
            regionPath  = new GraphicsPath();

            switch (cornerStyle)
            {
            case CornerStyle.Rounded:

                graphicPath.AddArc(0, 0, cornerSquare, cornerSquare, 180, 90);
                regionPath.AddArc(0, 0, cornerSquare, cornerSquare, 180, 90);
                graphicPath.AddLine(cornerSquare - cornerSquare / 2, 0, Width - cornerSquare + cornerSquare / 2 - 1, 0);
                regionPath.AddLine(cornerSquare - cornerSquare / 2, 0, Width - cornerSquare + cornerSquare / 2, 0);
                graphicPath.AddArc(Width - cornerSquare - 1, 0, cornerSquare, cornerSquare, -90, 90);
                regionPath.AddArc(Width - cornerSquare, 0, cornerSquare, cornerSquare, -90, 90);

                graphicPath.AddLine(Width - 1, cornerSquare - cornerSquare / 2, Width - 1, Height - cornerSquare + cornerSquare / 2);
                regionPath.AddLine(Width, cornerSquare - cornerSquare / 2, Width, Height - cornerSquare + cornerSquare / 2);
                graphicPath.AddArc(Width - cornerSquare - 1, Height - 1 - cornerSquare, cornerSquare, cornerSquare, 0, 90);
                regionPath.AddArc(Width - cornerSquare, Height - cornerSquare, cornerSquare, cornerSquare, 0, 90);
                graphicPath.AddLine(cornerSquare - cornerSquare / 2, Height - 1, Width - cornerSquare + cornerSquare / 2, Height - 1);
                regionPath.AddLine(cornerSquare - cornerSquare / 2, Height, Width - cornerSquare + cornerSquare / 2, Height);

                graphicPath.AddArc(0, Height - cornerSquare - 1, cornerSquare, cornerSquare, 90, 90);
                regionPath.AddArc(0, Height - cornerSquare, cornerSquare, cornerSquare, 90, 90);

                graphicPath.AddLine(0, cornerSquare - cornerSquare / 2, 0, Height - cornerSquare + cornerSquare / 2);
                regionPath.AddLine(0, cornerSquare - cornerSquare / 2, 0, Height - cornerSquare + cornerSquare / 2);
                //this.Region = new Region(graphicPath);

                //this.Region = new Region(graphicPath);
                break;

            case CornerStyle.Normal:

                graphicPath.AddLine(0, 0, Width - 1, 0);
                regionPath.AddLine(0, 0, Width, 0);
                graphicPath.AddLine(Width - 1, 0, Width - 1, Height - 1);
                regionPath.AddLine(Width, 0, Width, Height);
                graphicPath.AddLine(Width - 1, Height - 1, 0, Height - 1);
                regionPath.AddLine(Width, Height, 0, Height);
                graphicPath.AddLine(0, Height - 1, 0, 0);
                regionPath.AddLine(0, Height, 0, 0);
                break;

            default:
                throw new ApplicationException("Unrecognized style for rendering the corners");
                //break;
            }
        }
Esempio n. 22
0
    public GraphicsPath DrawHeart(float Xc, float Yc)
    {
        GraphicsPath gp = new GraphicsPath();

        Rectangle HeartTopLeftSquare = new Rectangle((int)Xc, (int)Yc, (int)RadiusOuter, (int)RadiusOuter);
        Rectangle HeartTopRightSquare = new Rectangle((int)Xc + (int)RadiusOuter, (int)Yc, (int)RadiusOuter, (int)RadiusOuter);

        gp.AddArc(HeartTopLeftSquare, 135f, 225f);
        gp.AddArc(HeartTopRightSquare, 180f, 225f);
        gp.AddLine((int)(Xc + (RadiusOuter * 2) - (1 - Math.Sin(45 / 180 * Math.PI)) * RadiusOuter / 2), (int)(Yc + RadiusOuter / 2 + Math.Sin(45 / 180 * Math.PI) * RadiusOuter / 2), (int)(Xc + RadiusOuter), (int)(Yc + (RadiusOuter * 2)));
        gp.AddLine((int)(Xc + RadiusOuter / 2 - Math.Sin(45 / 180 * Math.PI) * RadiusOuter / 2), (int)(Yc + RadiusOuter / 2 + Math.Sin(45 / 180 * Math.PI) * RadiusOuter / 2), (int)(Xc + RadiusOuter), (int)(Yc + (RadiusOuter * 2)));
        return gp;
    }
Esempio n. 23
0
        public PictureBox cutImageTopRight(Bitmap img, Size z)
        {
            sizeOriginal = z;
            double r         = ratio * sizeOriginal.Width / 2;
            double dCut      = ratioCut * r * 2;                                 //  phần trong dường tròn
            double hCut      = r - dCut;                                         // từ mặt đến tâm đường tròn
            float  angle     = (float)(Math.Acos(hCut / r) * 2 * 180 / Math.PI); //cung tròn trong
            double wCut      = 2 * Math.Sqrt(r * r - hCut * hCut);               // hình chiếu của tâm dường tròn đến điểm cắt
            int    dY        = (int)(2 * r - dCut);                              // phần lồi
            int    hOfCenter = sizeOriginal.Height - 2 * dY;
            var    bmp       = new Bitmap(sizeOriginal.Width, sizeOriginal.Height);
            float  sweepA    = 360 - angle;
            float  startA    = (180 + angle) / 2;

            var gPath = new GraphicsPath();

            gPath.AddLine(0, 0, (int)((sizeOriginal.Width - wCut) / 2), 0);
            //gPath.AddArc((float)(sizeOriginal.Width / 2 - r), 0, (float)(2 * r), (float)(2 * r), startA, sweepA);
            gPath.AddLine((int)((sizeOriginal.Width + wCut) / 2), 0, sizeOriginal.Width - dY, 0);
            ////////////////
            ///Right
            gPath.AddLine(sizeOriginal.Width, 0, sizeOriginal.Width, (int)(dY + (hOfCenter - wCut) / 2));

            gPath.AddLine(sizeOriginal.Width, (int)(dY + (hOfCenter + wCut) / 2), sizeOriginal.Width, 2 * dY + hOfCenter);
            //////////////////
            ///Bottom

            //gPath.AddLine(sizeOriginal.Width - dY, 2 * dY + hOfCenter, (int)((sizeOriginal.Width + wCut) / 2), 2 * dY + hOfCenter);
            //startA = (180 - angle) / 2;
            //gPath.AddArc((float)(sizeOriginal.Width / 2 - r), (float)(dY + hOfCenter), (float)(2 * r), (float)(2 * r), startA, -sweepA);
            //gPath.AddLine((int)((sizeOriginal.Width - wCut) / 2), 2 * dY + hOfCenter, (float)dY, 2 * dY + hOfCenter);
            gPath.AddLine(sizeOriginal.Width - dY, 2 * dY + hOfCenter, (int)((sizeOriginal.Width + wCut) / 2), 2 * dY + hOfCenter);
            startA = (180 - angle) / 2;
            gPath.AddArc((float)(sizeOriginal.Width / 2 - r), (float)(dY + hOfCenter), (float)(2 * r), (float)(2 * r), startA, -sweepA);
            gPath.AddLine((int)((sizeOriginal.Width - wCut) / 2), 2 * dY + hOfCenter, (float)dY, 2 * dY + hOfCenter);
            /////////////////////
            //////left

            //gPath.AddLine(dY, (2 * dY + hOfCenter), dY, (int)(dY + ((hOfCenter + wCut)) / 2));
            //startA = angle / 2;
            //gPath.AddArc(0, (float)(dY + (hOfCenter - wCut) / 2), (float)(2 * r), (float)(2 * r), startA, sweepA);
            //gPath.AddLine(dY, (int)(dY + (hOfCenter - wCut) / 2), dY, 0);
            gPath.AddLine(0, (2 * dY + hOfCenter), 0, (int)(dY + ((hOfCenter + wCut)) / 2));
            startA = 180 - angle / 2;
            gPath.AddArc((float)-dCut, (float)(dY + (hOfCenter - wCut) / 2), (float)(2 * r), (float)(2 * r), startA, -sweepA);
            gPath.AddLine(0, (int)(dY + (hOfCenter - wCut) / 2), 0, dY);

            using (var g = Graphics.FromImage(bmp))
            {
                g.Clip = new Region(gPath);
                g.DrawImage(img, 0, 0, bmp.Width, bmp.Height);
                if (isHL)
                {
                    g.DrawPath(pen, gPath);
                }
                //g.DrawPath(pen, gPath);
            }
            var picB = new PictureBox();

            picB.Image?.Dispose();
            picB.Image  = bmp;
            picB.Region = new Region(gPath);
            picB.Size   = z;
            ///////////
            return(picB);
        }
Esempio n. 24
0
    private void Draw3DBorder(Graphics g, float offset, Brush color, bool fill, float r, float percent)
    {
        int pen_width = 2;
        float x = this.ClientRectangle.Left + (pen_width / 2) + offset;
        float y = this.ClientRectangle.Top + (pen_width / 2) + offset;
        float w = (this.ClientRectangle.Width - (pen_width / 2 + 2 + offset * 2)) * percent;
        float h = this.ClientRectangle.Height - (pen_width / 2 + 2 + offset * 2);

        Pen pen = new Pen(color, (float)pen_width);
        GraphicsPath path = new GraphicsPath();

        if (w < 2 * r) {
            w = 2 * r;
        }

        path.AddLine(x + r, y, x + (w - r * 2), y);
        path.AddArc(x + w - r * 2, y, r * 2, r * 2, 270, 90);
        path.AddLine(x + w, y + r, x + w, y + h - r * 2);
        path.AddArc(x + w - r * 2, y + h - r * 2, r * 2, r * 2, 0, 90);
        path.AddLine(x + w - r * 2, y + h, x + r, y + h);
        path.AddArc(x, y + h - r * 2, r * 2, r * 2, 90, 90);
        path.AddLine(x, y + h - r * 2, x, y + r);
        path.AddArc(x, y, r * 2, r * 2, 180, 90);
        path.CloseFigure();

        g.SmoothingMode = SmoothingMode.AntiAlias;
        if (fill) {
            g.FillPath(color, path);
        } else {
            g.DrawPath(pen, path);
        }
    }
Esempio n. 25
0
        /// <summary>
        /// Draw horizontal button back on  the graphics specified.
        /// </summary>
        /// <param name="graphics">Button graphics object.</param>
        private void DrawHorizontalButtonBack(Graphics graphics)
        {
            // Define button radius
            int radius = (int)Math.Round(this.ClientRectangle.Height / 3.0);

            // Draw background image
            VerticalTabControl tabControl = this.Parent as VerticalTabControl;

            if (tabControl != null && tabControl.BackgroundImage != null)
            {
                int height = tabControl.GetButtonHeight() + 1;

                // Draw image in the background of the tab controls.
                // Image must be aligne to the bottom-right corner of the tabs area.
                Rectangle destRect = new Rectangle(
                    tabControl.Right - tabControl.BackgroundImage.Width + tabControl.BackImageOffsetX - this.Left,
                    0,
                    tabControl.BackgroundImage.Width,
                    height);
                ImageAttributes imageAttributes = new ImageAttributes();
                graphics.DrawImage(
                    tabControl.BackgroundImage,
                    destRect,
                    0,
                    tabControl.BackImageOffsetY + this.Top,
                    tabControl.BackgroundImage.Width,
                    height,
                    GraphicsUnit.Pixel,
                    imageAttributes);
            }

            // Create button border path
            using (GraphicsPath buttonPath = new GraphicsPath())
            {
                // Left vertical line
                buttonPath.AddLine(
                    this.ClientRectangle.X,
                    this.ClientRectangle.Bottom,
                    this.ClientRectangle.X,
                    this.ClientRectangle.Y + radius);

                // Top left arc
                buttonPath.AddArc(
                    this.ClientRectangle.X,
                    this.ClientRectangle.Y,
                    2 * radius,
                    2 * radius,
                    180,
                    90);

                // Top horizontal line
                buttonPath.AddLine(
                    this.ClientRectangle.X + radius,
                    this.ClientRectangle.Y,
                    this.ClientRectangle.Right - radius,
                    this.ClientRectangle.Y);

                // Top right arc
                buttonPath.AddArc(
                    this.ClientRectangle.Right - 1 - 2 * radius,
                    this.ClientRectangle.Y,
                    2 * radius,
                    2 * radius,
                    270,
                    90);

                // Right vertical line
                buttonPath.AddLine(
                    this.ClientRectangle.Right - 1,
                    this.ClientRectangle.Y + radius,
                    this.ClientRectangle.Right - 1,
                    this.ClientRectangle.Bottom);

                // Bottom horizontal line
                if (!this.SelectedTab)
                {
                    buttonPath.AddLine(
                        this.ClientRectangle.X,
                        this.ClientRectangle.Bottom - 1,
                        this.ClientRectangle.Right,
                        this.ClientRectangle.Bottom - 1);
                }

                // Fill button background
                if (this.SelectedTab)
                {
                    Rectangle brushRect = this.ClientRectangle;
                    using (LinearGradientBrush backBrush = new LinearGradientBrush(brushRect, this.selectedGradientBackColor, this.BackColor, 90))
                    {
                        Blend blend = new Blend(3);
                        blend.Positions[0] = 0.0f;
                        blend.Positions[1] = 0.8f;
                        blend.Positions[2] = 1.0f;
                        blend.Factors[0]   = 0.0f;
                        blend.Factors[1]   = 1.0f;
                        blend.Factors[2]   = 1.0f;

                        backBrush.Blend = blend;
                        graphics.FillPath(backBrush, buttonPath);
                    }
                }
                else
                {
                    using (SolidBrush backBrush = new SolidBrush((this.SelectedTab) ? this.BackColor : nonSelectedBackColor))
                    {
                        graphics.FillPath(backBrush, buttonPath);
                    }
                }

                // Draw button border using Anti-Aliasing
                using (Pen pen = new Pen(this.borderColor, 1))
                {
                    SmoothingMode oldMode = graphics.SmoothingMode;
                    graphics.SmoothingMode = SmoothingMode.AntiAlias;
                    graphics.DrawPath(pen, buttonPath);
                    graphics.SmoothingMode = oldMode;
                }
            }
        }
        /// <summary>
        /// 建立带有圆角样式和标题的路径。
        /// </summary>
        /// <param name="rect">用来简历路径的矩形。</param>
        /// <param name="style">圆角样式。</param>
        /// <param name="radius">圆角大小。</param>
        /// <param name="tabSize">标题大小。</param>
        /// <param name="tabRound">标题是否圆角。</param>
        /// <param name="tabRadius">标题圆角大小。</param>
        /// <param name="correct">是否把矩形长宽减 1,以便画出边框。</param>
        /// <returns>简历的路径。</returns>
        public static GraphicsPath CreateGroupBoxTabGraphicsPath(Rectangle rect, RoundStyle style, float radius, Size tabSize, bool tabRound, float tabRadius, bool correct)
        {
            //校正
            if (correct)
            {
                rect.Width--;
                rect.Height--;
            }
            style    = (float.IsNaN(radius) || radius <= 0f) ? RoundStyle.None : style;
            tabRound = (float.IsNaN(tabRadius) || tabRadius <= 0f) ? false : tabRound;

            //定义
            GraphicsPath path        = new GraphicsPath();
            Rectangle    tabRect     = new Rectangle(rect.Location, tabSize);
            float        diameter    = radius * 2;
            float        tabDiameter = tabRadius * 2;
            Point        pt;

            //左上
            if ((style & RoundStyle.TopLeft) == 0)
            {
                pt = new Point(rect.X, rect.Y);
                path.AddLine(pt, pt);
            }
            else
            {
                path.AddArc(rect.X, rect.Y, diameter, diameter, 180, 90);
            }

            //Tab右上
            if (tabRound)
            {
                if (tabRadius > tabRect.Height)//不到90度
                {
                    double radians = Math.Acos((tabRadius - tabRect.Height) / tabRadius);
                    path.AddArc((float)(tabRect.Right - tabRadius * Math.Sin(radians) - tabRadius),
                                tabRect.Y, tabDiameter, tabDiameter, 270, (float)MathEx.ToDegrees(radians));
                }
                else//到90度
                {
                    path.AddArc(tabRect.Right - tabDiameter, tabRect.Y, tabDiameter, tabDiameter, 270, 90);

                    //Tab右下
                    pt = new Point(tabRect.Right, tabRect.Bottom);
                    path.AddLine(pt, pt);
                }
            }
            else
            {
                pt = new Point(tabRect.Right, tabRect.Y);
                path.AddLine(pt, pt);

                //Tab右下
                pt = new Point(tabRect.Right, tabRect.Bottom);
                path.AddLine(pt, pt);
            }

            //右上
            if ((style & RoundStyle.TopRight) == 0)
            {
                pt = new Point(rect.Right, tabRect.Bottom);
                path.AddLine(pt, pt);
            }
            else
            {
                path.AddArc(rect.Right - diameter, tabRect.Bottom, diameter, diameter, 270, 90);
            }

            //右下
            if ((style & RoundStyle.BottomRight) == 0)
            {
                pt = new Point(rect.Right, rect.Bottom);
                path.AddLine(pt, pt);
            }
            else
            {
                path.AddArc(rect.Right - diameter, rect.Bottom - diameter, diameter, diameter, 0, 90);
            }

            //左下
            if ((style & RoundStyle.BottomLeft) == 0)
            {
                pt = new Point(rect.X, rect.Bottom);
                path.AddLine(pt, pt);
            }
            else
            {
                path.AddArc(rect.X, rect.Bottom - diameter, diameter, diameter, 90, 90);
            }

            //闭合返回
            path.CloseFigure();
            return(path);
        }
Esempio n. 27
0
        /// <summary>
        /// 建立带有圆角样式的路径。
        /// </summary>
        /// <param name="rect">用来建立路径的矩形。</param>
        /// <param name="_radius">圆角的大小。</param>
        /// <param name="style">圆角的样式。</param>
        /// <param name="correction">是否把矩形长宽减 1,以便画出边框。</param>
        /// <returns>建立的路径。</returns>
        public static GraphicsPath CreatePath(
            Rectangle rect, int radius, RoundStyle style, bool correction)
        {
            GraphicsPath path             = new GraphicsPath();
            int          radiusCorrection = correction ? 1 : 0;

            switch (style)
            {
            case RoundStyle.None:
                path.AddRectangle(rect);
                break;

            case RoundStyle.All:
                path.AddArc(rect.X, rect.Y, radius, radius, 180, 90);
                path.AddArc(
                    rect.Right - radius - radiusCorrection,
                    rect.Y,
                    radius,
                    radius,
                    270,
                    90);
                path.AddArc(
                    rect.Right - radius - radiusCorrection,
                    rect.Bottom - radius - radiusCorrection,
                    radius,
                    radius, 0, 90);
                path.AddArc(
                    rect.X,
                    rect.Bottom - radius - radiusCorrection,
                    radius,
                    radius,
                    90,
                    90);
                break;

            case RoundStyle.Left:
                path.AddArc(rect.X, rect.Y, radius, radius, 180, 90);
                path.AddLine(
                    rect.Right - radiusCorrection, rect.Y,
                    rect.Right - radiusCorrection, rect.Bottom - radiusCorrection);
                path.AddArc(
                    rect.X,
                    rect.Bottom - radius - radiusCorrection,
                    radius,
                    radius,
                    90,
                    90);
                break;

            case RoundStyle.Right:
                path.AddArc(
                    rect.Right - radius - radiusCorrection,
                    rect.Y,
                    radius,
                    radius,
                    270,
                    90);
                path.AddArc(
                    rect.Right - radius - radiusCorrection,
                    rect.Bottom - radius - radiusCorrection,
                    radius,
                    radius,
                    0,
                    90);
                path.AddLine(rect.X, rect.Bottom - radiusCorrection, rect.X, rect.Y);
                break;

            case RoundStyle.Top:
                path.AddArc(rect.X, rect.Y, radius, radius, 180, 90);
                path.AddArc(
                    rect.Right - radius - radiusCorrection,
                    rect.Y,
                    radius,
                    radius,
                    270,
                    90);
                path.AddLine(
                    rect.Right - radiusCorrection, rect.Bottom - radiusCorrection,
                    rect.X, rect.Bottom - radiusCorrection);
                break;

            case RoundStyle.Bottom:
                path.AddArc(
                    rect.Right - radius - radiusCorrection,
                    rect.Bottom - radius - radiusCorrection,
                    radius,
                    radius,
                    0,
                    90);
                path.AddArc(
                    rect.X,
                    rect.Bottom - radius - radiusCorrection,
                    radius,
                    radius,
                    90,
                    90);
                path.AddLine(rect.X, rect.Y, rect.Right - radiusCorrection, rect.Y);
                break;
            }
            path.CloseFigure();

            return(path);
        }
Esempio n. 28
0
        private static GraphicsPath GenerateRoundedRectangle(
            this Graphics graphics,
            RectangleF rectangle,
            float radius,
            RectangleEdgeFilter filter)
        {
            float diameter;
            var   path = new GraphicsPath();

            if (radius <= 0.0F || filter == RectangleEdgeFilter.None)
            {
                path.AddRectangle(rectangle);
                path.CloseFigure();
                return(path);
            }

            if (radius >= Math.Min(rectangle.Width, rectangle.Height) / 2.0)
            {
                return(graphics.GenerateCapsule(rectangle));
            }
            diameter = radius * 2.0F;
            var sizeF = new SizeF(diameter, diameter);
            var arc   = new RectangleF(rectangle.Location, sizeF);

            if ((RectangleEdgeFilter.TopLeft & filter) == RectangleEdgeFilter.TopLeft)
            {
                path.AddArc(arc, 180, 90);
            }
            else
            {
                path.AddLine(arc.X, arc.Y + arc.Height, arc.X, arc.Y);
                path.AddLine(arc.X, arc.Y, arc.X + arc.Width, arc.Y);
            }

            arc.X = rectangle.Right - diameter;
            if ((RectangleEdgeFilter.TopRight & filter) == RectangleEdgeFilter.TopRight)
            {
                path.AddArc(arc, 270, 90);
            }
            else
            {
                path.AddLine(arc.X, arc.Y, arc.X + arc.Width, arc.Y);
                path.AddLine(arc.X + arc.Width, arc.Y + arc.Height, arc.X + arc.Width, arc.Y);
            }

            arc.Y = rectangle.Bottom - diameter;
            if ((RectangleEdgeFilter.BottomRight & filter) == RectangleEdgeFilter.BottomRight)
            {
                path.AddArc(arc, 0, 90);
            }
            else
            {
                path.AddLine(arc.X + arc.Width, arc.Y, arc.X + arc.Width, arc.Y + arc.Height);
                path.AddLine(arc.X, arc.Y + arc.Height, arc.X + arc.Width, arc.Y + arc.Height);
            }

            arc.X = rectangle.Left;
            if ((RectangleEdgeFilter.BottomLeft & filter) == RectangleEdgeFilter.BottomLeft)
            {
                path.AddArc(arc, 90, 90);
            }
            else
            {
                path.AddLine(arc.X + arc.Width, arc.Y + arc.Height, arc.X, arc.Y + arc.Height);
                path.AddLine(arc.X, arc.Y + arc.Height, arc.X, arc.Y);
            }

            path.CloseFigure();
            return(path);
        }
        protected override void OnPaint(PaintEventArgs pevent)
        {
            //base.OnPaint(pevent);

            if (inOnPaint)
            {
                return;
            }

            inOnPaint = true;

            try
            {
                Graphics gr = pevent.Graphics;

                gr.Clear(this.BackColor);

                gr.SmoothingMode = SmoothingMode.AntiAlias;

                Rectangle outside = new Rectangle(0, 0, this.Width, this.Height);

                LinearGradientBrush linear = new LinearGradientBrush(outside, BGGradTop, BGGradBot, LinearGradientMode.Vertical);

                Pen mypen = new Pen(Outline, 1);

                GraphicsPath outline = new GraphicsPath();

                float wid = this.Height / 3f;

                wid = 1;

                int width  = this.Width - 1;
                int height = this.Height - 1;

                // tl
                outline.AddArc(0, 0, wid, wid, 180, 90);
                // top line
                outline.AddLine(wid, 0, width - wid, 0);
                // tr
                outline.AddArc(width - wid, 0, wid, wid, 270, 90);
                // br
                outline.AddArc(width - wid, height - wid, wid, wid, 0, 90);
                // bottom line
                outline.AddLine(wid, height, width - wid, height);
                // bl
                outline.AddArc(0, height - wid, wid, wid, 90, 90);
                // left line
                outline.AddLine(0, height - wid, 0, wid - wid / 2);


                gr.FillPath(linear, outline);

                gr.DrawPath(mypen, outline);

                SolidBrush mybrush = new SolidBrush(TextColor);

                if (_mouseover)
                {
                    SolidBrush brush = new SolidBrush(Color.FromArgb(73, 0x2b, 0x3a, 0x03));

                    gr.FillPath(brush, outline);
                }
                if (_mousedown)
                {
                    SolidBrush brush = new SolidBrush(Color.FromArgb(73, 0x2b, 0x3a, 0x03));

                    gr.FillPath(brush, outline);
                }

                if (!this.Enabled)
                {
                    SolidBrush brush = new SolidBrush(Color.FromArgb(150, 0x2b, 0x3a, 0x03));

                    gr.FillPath(brush, outline);
                }


                StringFormat stringFormat = new StringFormat();
                stringFormat.Alignment     = StringAlignment.Center;
                stringFormat.LineAlignment = StringAlignment.Center;

                string display = this.Text;
                int    amppos  = display.IndexOf('&');
                if (amppos != -1)
                {
                    display = display.Remove(amppos, 1);
                }

                gr.DrawString(display, this.Font, mybrush, outside, stringFormat);
            }
            catch { }

            inOnPaint = false;
        }
Esempio n. 30
0
    public void DrawButton(PaintEventArgs e, ToggleButtonState toggleState, DisplayType displayMode, Font font, ActiveStateCollection activeState, InactiveStateCollection inactiveState, RightToLeft righttoLeft, bool isMouseHover, ToggleButton togglebutton)
    {
        string    displaytext = toggleState == ToggleButtonState.Active ? activeState.Text : inactiveState.Text;
        SizeF     textsize    = e.Graphics.MeasureString(displaytext, font);
        Rectangle controlrect = new Rectangle(e.ClipRectangle.X + 1, e.ClipRectangle.Y + 1, e.ClipRectangle.Width - 4, e.ClipRectangle.Height - 4);

        e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
        GraphicsPath gp = new GraphicsPath();

        using (LinearGradientBrush br = new LinearGradientBrush(e.ClipRectangle, ColorTranslator.FromHtml("#007feb"), ColorTranslator.FromHtml("#51a7f2"), LinearGradientMode.Vertical))
        {
            if (controlrect.Height > 1)
            {
                gp.AddArc(controlrect.X, controlrect.Y, controlrect.Height, controlrect.Height, 180, 90);
                gp.AddArc(controlrect.X + controlrect.Width - controlrect.Height, controlrect.Y, controlrect.Height, controlrect.Height, 270, 90);
                gp.AddArc(controlrect.X + controlrect.Width - controlrect.Height, controlrect.Y + controlrect.Height - controlrect.Height, controlrect.Height, controlrect.Height, 0, 90);
                gp.AddArc(controlrect.X, controlrect.Y + controlrect.Height - controlrect.Height, controlrect.Height, controlrect.Height, 90, 90);
                gp.CloseFigure();
                e.Graphics.DrawPath(new Pen(ColorTranslator.FromHtml("#002f69"), 2), gp);
            }
        }
        GraphicsPath gp1 = new GraphicsPath();

        using (LinearGradientBrush br = new LinearGradientBrush(e.ClipRectangle, ColorTranslator.FromHtml("#007feb"), ColorTranslator.FromHtml("#51a7f2"), LinearGradientMode.Vertical))
        {
            if (controlrect.Height > 1)
            {
                gp1.AddArc(controlrect.X, controlrect.Y + 1, controlrect.Height + 2, controlrect.Height, 180, 90);
                gp1.AddArc(controlrect.X + controlrect.Width - controlrect.Height, controlrect.Y, controlrect.Height, controlrect.Height, 270, 90);
                gp1.AddArc(controlrect.X + 1 + controlrect.Width - controlrect.Height, controlrect.Y + controlrect.Height - controlrect.Height, controlrect.Height, controlrect.Height, 0, 90);
                gp1.AddArc(controlrect.X, controlrect.Y + controlrect.Height - controlrect.Height, controlrect.Height, controlrect.Height, 90, 90);
                gp1.CloseFigure();
                e.Graphics.FillPath(br, gp1);
                gp1.Dispose();
            }
        }
        GraphicsPath gp2 = new GraphicsPath();

        using (LinearGradientBrush br = new LinearGradientBrush(e.ClipRectangle, ColorTranslator.FromHtml("#51a7f2"), ColorTranslator.FromHtml("#51a7f2"), LinearGradientMode.Vertical))
        {
            if (controlrect.Height > 1)
            {
                gp2.AddArc(controlrect.X + 5, controlrect.Y + controlrect.Height / 2, controlrect.Height - controlrect.Height / 2, controlrect.Height / 2, 180, 90);
                gp2.AddArc(controlrect.X + 5 + controlrect.Width - controlrect.Height, controlrect.Y + controlrect.Height / 2, controlrect.Height - controlrect.Height / 2, controlrect.Height / 2, 270, 90);
                gp2.AddArc(controlrect.X + 5 + controlrect.Width - controlrect.Height, controlrect.Y + controlrect.Height - controlrect.Height + controlrect.Height / 2, controlrect.Height - controlrect.Height / 2, controlrect.Height / 2, 0, 90);
                gp2.AddArc(controlrect.X + 5, controlrect.Y + controlrect.Height - controlrect.Height + controlrect.Height / 2, controlrect.Height - controlrect.Height / 2, controlrect.Height / 2, 90, 90);
                gp2.CloseFigure();
                e.Graphics.FillPath(br, gp2);
                gp2.Dispose();
            }
        }
        if (isMouseHover)
        {
            using (SolidBrush br = new SolidBrush(ColorTranslator.FromHtml("#51a7f2")))
            {
                e.Graphics.FillPath(br, gp);
            }
        }
        PointF pt1 = new PointF(e.ClipRectangle.X + e.ClipRectangle.Width / 2 - textsize.Width / 2, e.ClipRectangle.Y + e.ClipRectangle.Height / 2 - textsize.Height / 2);

        using (SolidBrush br = new SolidBrush(activeState.ForeColor))
        {
            if (displayMode == DisplayType.Text)
            {
                e.Graphics.DrawString(displaytext, font, br, pt1);
            }
        }
        gp.Dispose();
    }
Esempio n. 31
0
        private GraphicsPath BuildHolderButtonFrame(Rectangle rcBtn, int lFrameWidth, int lFrameHeight)
        {
            GraphicsPath XHolderBtnPath = new GraphicsPath();

            XHolderBtnPath.AddArc(
                rcBtn.Left - 2,
                rcBtn.Top,
                rcBtn.Height / 2,
                rcBtn.Height / 2,
                180,
                90);
            XHolderBtnPath.AddLine(
                rcBtn.Left + rcBtn.Height / 2,
                rcBtn.Top,
                rcBtn.Right - 2,
                rcBtn.Top);
            XHolderBtnPath.AddArc(
                rcBtn.Right - rcBtn.Height / 2 + 2,
                rcBtn.Top,
                rcBtn.Height / 2,
                rcBtn.Height / 2,
                -90,
                90);
            XHolderBtnPath.AddLine(
                rcBtn.Right + 2,
                rcBtn.Top + rcBtn.Height / 2,
                rcBtn.Right + 2,
                rcBtn.Top + rcBtn.Height + 2 + rcBtn.Height / 2 - 8);

            XHolderBtnPath.AddLine(
                rcBtn.Right + 2,
                rcBtn.Top + rcBtn.Height + 2 + rcBtn.Height / 2 - 8,
                rcBtn.Right + lFrameWidth,
                rcBtn.Top + rcBtn.Height + 2 + rcBtn.Height / 2 - 8);

            XHolderBtnPath.AddArc(
                rcBtn.Right + lFrameWidth,
                rcBtn.Top + rcBtn.Height + 2 + rcBtn.Height / 2 - 8,
                rcBtn.Height / 2,
                rcBtn.Height / 2,
                -90,
                90);

            XHolderBtnPath.AddLine(
                rcBtn.Right + lFrameWidth + rcBtn.Height / 2,
                rcBtn.Top + rcBtn.Height + 2 - 8 + rcBtn.Height / 2,
                rcBtn.Right + lFrameWidth + rcBtn.Height / 2,
                rcBtn.Top + rcBtn.Height + 2 - 8 + rcBtn.Height / 2 + lFrameHeight);

            XHolderBtnPath.AddLine(
                rcBtn.Right + lFrameWidth + rcBtn.Height / 2,
                rcBtn.Top + rcBtn.Height + 2 - 8 + rcBtn.Height / 2 + lFrameHeight,
                rcBtn.Left,
                rcBtn.Top + rcBtn.Height + 2 - 8 + rcBtn.Height / 2 + lFrameHeight
                );

            XHolderBtnPath.AddLine(
                rcBtn.Left - 2,
                rcBtn.Top + rcBtn.Height + 2 - 8 + rcBtn.Height / 2 + lFrameHeight,
                rcBtn.Left - 2,
                rcBtn.Top + rcBtn.Height / 2 - 4
                );

            return(XHolderBtnPath);
        }
Esempio n. 32
0
        public static GraphicsPath Create(int x, int y, int width, int height, int radius, RectangleCorners corners)
        {
            int xw   = x + width;
            int yh   = y + height;
            int xwr  = xw - radius;
            int yhr  = yh - radius;
            int xr   = x + radius;
            int yr   = y + radius;
            int r2   = radius * 2;
            int xwr2 = xw - r2;
            int yhr2 = yh - r2;

            GraphicsPath p = new GraphicsPath();

            p.StartFigure();

            //Top Left Corner
            if ((RectangleCorners.TopLeft & corners) == RectangleCorners.TopLeft)
            {
                p.AddArc(x, y, r2, r2, 180, 90);
            }
            else
            {
                p.AddLine(x, yr, x, y);
                p.AddLine(x, y, xr, y);
            }

            //Top Edge
            p.AddLine(xr, y, xwr, y);

            //Top Right Corner
            if ((RectangleCorners.TopRight & corners) == RectangleCorners.TopRight)
            {
                p.AddArc(xwr2, y, r2, r2, 270, 90);
            }
            else
            {
                p.AddLine(xwr, y, xw, y);
                p.AddLine(xw, y, xw, yr);
            }

            //Right Edge
            p.AddLine(xw, yr, xw, yhr);

            //Bottom Right Corner
            if ((RectangleCorners.BottomRight & corners) == RectangleCorners.BottomRight)
            {
                p.AddArc(xwr2, yhr2, r2, r2, 0, 90);
            }
            else
            {
                p.AddLine(xw, yhr, xw, yh);
                p.AddLine(xw, yh, xwr, yh);
            }

            //Bottom Edge
            p.AddLine(xwr, yh, xr, yh);

            //Bottom Left Corner
            if ((RectangleCorners.BottomLeft & corners) == RectangleCorners.BottomLeft)
            {
                p.AddArc(x, yhr2, r2, r2, 90, 90);
            }
            else
            {
                p.AddLine(xr, yh, x, yh);
                p.AddLine(x, yh, x, yhr);
            }

            //Left Edge
            p.AddLine(x, yhr, x, yr);

            p.CloseFigure();
            return(p);
        }
Esempio n. 33
0
 public void AddArc(Rectangle rect, float startAngle, float sweepAngle)
 {
     Changed();
     gdiPath.AddArc(rect, startAngle, sweepAngle);
 }
Esempio n. 34
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            Point StartPoint = new Point(0, 0);
            Point EndPoint   = new Point(0, this.Height);

            if (_ProgressDirection == ProgressDir.Vertical)
            {
                EndPoint = new Point(this.Width, 0);
            }

            using (GraphicsPath gp = new GraphicsPath())
            {
                Rectangle rec = new Rectangle(0, 0, this.Width, this.Height);
                int       rad = Convert.ToInt32(rec.Height / 2.5);
                if (rec.Width < rec.Height)
                {
                    rad = Convert.ToInt32(rec.Width / 2.5);
                }

                using (LinearGradientBrush _BackColorBrush = new LinearGradientBrush(StartPoint, EndPoint, _BackColor, _GradiantColor))
                {
                    _BackColorBrush.Blend = bBlend;
                    if (_RoundedCorners)
                    {
                        gp.AddArc(rec.X, rec.Y, rad, rad, 180, 90);
                        gp.AddArc(rec.Right - (rad), rec.Y, rad, rad, 270, 90);
                        gp.AddArc(rec.Right - (rad), rec.Bottom - (rad), rad, rad, 0, 90);
                        gp.AddArc(rec.X, rec.Bottom - (rad), rad, rad, 90, 90);
                        gp.CloseFigure();
                        e.Graphics.FillPath(_BackColorBrush, gp);
                    }
                    else
                    {
                        e.Graphics.FillRectangle(_BackColorBrush, rec);
                    }
                }

                if (_Value > _Minimum)
                {
                    int lngth = Convert.ToInt32((double)(this.Width / (double)(_Maximum - _Minimum)) * _Value);
                    if (_ProgressDirection == ProgressDir.Vertical)
                    {
                        lngth      = Convert.ToInt32((double)(this.Height / (double)(_Maximum - _Minimum)) * _Value);
                        rec.Y      = rec.Height - lngth;
                        rec.Height = lngth;
                    }
                    else
                    {
                        rec.Width = lngth;
                    }

                    using (LinearGradientBrush _ProgressBrush = new LinearGradientBrush(StartPoint, EndPoint, _ProgressColor, _GradiantColor))
                    {
                        _ProgressBrush.Blend = bBlend;
                        if (_RoundedCorners)
                        {
                            if (_ProgressDirection == ProgressDir.Horizontal)
                            {
                                rec.Height -= 1;
                            }
                            else
                            {
                                rec.Width -= 1;
                            }

                            using (GraphicsPath gp2 = new GraphicsPath())
                            {
                                gp2.AddArc(rec.X, rec.Y, rad, rad, 180, 90);
                                gp2.AddArc(rec.Right - (rad), rec.Y, rad, rad, 270, 90);
                                gp2.AddArc(rec.Right - (rad), rec.Bottom - (rad), rad, rad, 0, 90);
                                gp2.AddArc(rec.X, rec.Bottom - (rad), rad, rad, 90, 90);
                                gp2.CloseFigure();
                                using (GraphicsPath gp3 = new GraphicsPath())
                                {
                                    using (Region rgn = new Region(gp))
                                    {
                                        rgn.Intersect(gp2);
                                        gp3.AddRectangles(rgn.GetRegionScans(new Matrix()));
                                    }
                                    e.Graphics.FillPath(_ProgressBrush, gp3);
                                }
                            }
                        }
                        else
                        {
                            e.Graphics.FillRectangle(_ProgressBrush, rec);
                        }
                    }
                }

                if (_Image != null)
                {
                    if (_ImageLayout == ImageLayoutType.Stretch)
                    {
                        e.Graphics.DrawImage(_Image, 0, 0, this.Width, this.Height);
                    }
                    else if (_ImageLayout == ImageLayoutType.None)
                    {
                        e.Graphics.DrawImage(_Image, 0, 0);
                    }
                    else
                    {
                        int xx = Convert.ToInt32((this.Width / 2) - (_Image.Width / 2));
                        int yy = Convert.ToInt32((this.Height / 2) - (_Image.Height / 2));
                        e.Graphics.DrawImage(_Image, xx, yy);
                    }
                }

                if (_ShowPercentage | _ShowText)
                {
                    string perc = "";
                    if (_ShowText)
                    {
                        perc = this.Text;
                    }
                    if (_ShowPercentage)
                    {
                        perc += Convert.ToString(Convert.ToInt32(((double)100 / (double)(_Maximum - _Minimum)) * _Value)) + "%";
                    }
                    using (StringFormat sf = new StringFormat {
                        Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center
                    })
                    {
                        e.Graphics.DrawString(perc, this.Font, _ForeColorBrush, new Rectangle(0, 0, this.Width, this.Height), sf);
                    }
                }

                if (_Border)
                {
                    rec = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
                    if (_RoundedCorners)
                    {
                        gp.Reset();
                        gp.AddArc(rec.X, rec.Y, rad, rad, 180, 90);
                        gp.AddArc(rec.Right - (rad), rec.Y, rad, rad, 270, 90);
                        gp.AddArc(rec.Right - (rad), rec.Bottom - (rad), rad, rad, 0, 90);
                        gp.AddArc(rec.X, rec.Bottom - (rad), rad, rad, 90, 90);
                        gp.CloseFigure();
                        e.Graphics.DrawPath(_BorderPen, gp);
                    }
                    else
                    {
                        e.Graphics.DrawRectangle(_BorderPen, rec);
                    }
                }
            }
        }
Esempio n. 35
0
        /// <summary>
        /// 角丸を描く
        /// </summary>
        /// <param name="g"></param>
        private void PaintCorner(Graphics g)
        {
            // 描画品質設定
            SetSmoothMode(g);

            // 変数初期化
            int offset = shadowSize + GetHarfPenWidth();
            int w      = this.Width - cornerR;
            int h      = this.Height - cornerR;

            // 影用のパス初期化
            GraphicsPath shadowPath = null;

            if (shadowSize > 0)
            {
                shadowPath = GetShadowPath();
            }

            // 影用のブラシ初期化
            PathGradientBrush shadowBrush = null;

            if (shadowSize > 0)
            {
                shadowBrush = GetShadowBrush(shadowPath);
            }

            // 角丸用のペンとブラシ初期化
            Pen   cornerPen = new Pen(cornerColor, penWidth);
            Brush fillBrush = new SolidBrush(innerColor);

            // 角丸用のパスの初期化
            GraphicsPath graphPath = new GraphicsPath();

            graphPath.AddArc(offset, offset, cornerR, cornerR, 180, 90);
            graphPath.AddArc(w - offset, offset, cornerR, cornerR, 270, 90);
            graphPath.AddArc(w - offset, h - offset, cornerR, cornerR, 0, 90);
            graphPath.AddArc(offset, h - offset, cornerR, cornerR, 90, 90);
            graphPath.CloseFigure();

            // 影塗り
            if (shadowSize > 0)
            {
                g.FillPath(shadowBrush, shadowPath);
            }

            // 角丸用のパス塗り
            g.FillPath(fillBrush, graphPath);

            // ペンの太さが 1 以上なら角丸描画
            if (penWidth > 0)
            {
                g.DrawPath(cornerPen, graphPath);
            }

            // 後処理
            if (shadowSize > 0)
            {
                shadowPath.Dispose();
                shadowBrush.Dispose();
            }
            fillBrush.Dispose();
            cornerPen.Dispose();
        }
Esempio n. 36
0
    public static GraphicsPath RoundRect(Rectangle Rect, int Rounding, RoundingStyle Style = RoundingStyle.All)
    {
        GraphicsPath GP = new GraphicsPath();
        int AW = Rounding * 2;

        GP.StartFigure();

        if (Rounding == 0)
        {
            GP.AddRectangle(Rect);
            GP.CloseAllFigures();
            return GP;
        }

        switch (Style)
        {
            case RoundingStyle.All:
                GP.AddArc(new Rectangle(Rect.X, Rect.Y, AW, AW), -180, 90);
                GP.AddArc(new Rectangle(Rect.Width - AW + Rect.X, Rect.Y, AW, AW), -90, 90);
                GP.AddArc(new Rectangle(Rect.Width - AW + Rect.X, Rect.Height - AW + Rect.Y, AW, AW), 0, 90);
                GP.AddArc(new Rectangle(Rect.X, Rect.Height - AW + Rect.Y, AW, AW), 90, 90);
                break;
            case RoundingStyle.Top:
                GP.AddArc(new Rectangle(Rect.X, Rect.Y, AW, AW), -180, 90);
                GP.AddArc(new Rectangle(Rect.Width - AW + Rect.X, Rect.Y, AW, AW), -90, 90);
                GP.AddLine(new Point(Rect.X + Rect.Width, Rect.Y + Rect.Height), new Point(Rect.X, Rect.Y + Rect.Height));
                break;
            case RoundingStyle.Bottom:
                GP.AddLine(new Point(Rect.X, Rect.Y), new Point(Rect.X + Rect.Width, Rect.Y));
                GP.AddArc(new Rectangle(Rect.Width - AW + Rect.X, Rect.Height - AW + Rect.Y, AW, AW), 0, 90);
                GP.AddArc(new Rectangle(Rect.X, Rect.Height - AW + Rect.Y, AW, AW), 90, 90);
                break;
            case RoundingStyle.Left:
                GP.AddArc(new Rectangle(Rect.X, Rect.Y, AW, AW), -180, 90);
                GP.AddLine(new Point(Rect.X + Rect.Width, Rect.Y), new Point(Rect.X + Rect.Width, Rect.Y + Rect.Height));
                GP.AddArc(new Rectangle(Rect.X, Rect.Height - AW + Rect.Y, AW, AW), 90, 90);
                break;
            case RoundingStyle.Right:
                GP.AddLine(new Point(Rect.X, Rect.Y + Rect.Height), new Point(Rect.X, Rect.Y));
                GP.AddArc(new Rectangle(Rect.Width - AW + Rect.X, Rect.Y, AW, AW), -90, 90);
                GP.AddArc(new Rectangle(Rect.Width - AW + Rect.X, Rect.Height - AW + Rect.Y, AW, AW), 0, 90);
                break;
            case RoundingStyle.TopRight:
                GP.AddLine(new Point(Rect.X, Rect.Y + 1), new Point(Rect.X, Rect.Y));
                GP.AddArc(new Rectangle(Rect.Width - AW + Rect.X, Rect.Y, AW, AW), -90, 90);
                GP.AddLine(new Point(Rect.X + Rect.Width, Rect.Y + Rect.Height - 1), new Point(Rect.X + Rect.Width, Rect.Y + Rect.Height));
                GP.AddLine(new Point(Rect.X + 1, Rect.Y + Rect.Height), new Point(Rect.X, Rect.Y + Rect.Height));
                break;
            case RoundingStyle.BottomRight:
                GP.AddLine(new Point(Rect.X, Rect.Y + 1), new Point(Rect.X, Rect.Y));
                GP.AddLine(new Point(Rect.X + Rect.Width - 1, Rect.Y), new Point(Rect.X + Rect.Width, Rect.Y));
                GP.AddArc(new Rectangle(Rect.Width - AW + Rect.X, Rect.Height - AW + Rect.Y, AW, AW), 0, 90);
                GP.AddLine(new Point(Rect.X + 1, Rect.Y + Rect.Height), new Point(Rect.X, Rect.Y + Rect.Height));
                break;
        }

        GP.CloseAllFigures();

        return GP;
    }
Esempio n. 37
0
    private GraphicsPath RoundRectangle(Rectangle r, int radius, GroupBoxCorners corners)
    {
        GraphicsPath path = new GraphicsPath();
        if (r.Width <= 0 | r.Height <= 0)
          return path;

        int d = radius * 2;

        int nw = ((corners & GroupBoxCorners.NorthWest) == GroupBoxCorners.NorthWest ? d : 0);
        int ne = ((corners & GroupBoxCorners.NorthEast) == GroupBoxCorners.NorthEast ? d : 0);
        int se = ((corners & GroupBoxCorners.SouthEast) == GroupBoxCorners.SouthEast ? d : 0);
        int sw = ((corners & GroupBoxCorners.SouthWest) == GroupBoxCorners.SouthWest ? d : 0);

        path.AddLine(r.Left + nw, r.Top, r.Right - ne, r.Top);

        if (ne > 0)
        {
          path.AddArc(Rectangle.FromLTRB(r.Right - ne, r.Top, r.Right, r.Top + ne), -90, 90);
        }

        path.AddLine(r.Right, r.Top + ne, r.Right, r.Bottom - se);

        if (se > 0)
        {
          path.AddArc(Rectangle.FromLTRB(r.Right - se, r.Bottom - se, r.Right, r.Bottom), 0, 90);
        }

        path.AddLine(r.Right - se, r.Bottom, r.Left + sw, r.Bottom);

        if (sw > 0)
        {
          path.AddArc(Rectangle.FromLTRB(r.Left, r.Bottom - sw, r.Left + sw, r.Bottom), 90, 90);
        }

        path.AddLine(r.Left, r.Bottom - sw, r.Left, r.Top + nw);

        if (nw > 0)
        {
          path.AddArc(Rectangle.FromLTRB(r.Left, r.Top, r.Left + nw, r.Top + nw), 180, 90);
        }

        path.CloseFigure();
        return path;
    }
Esempio n. 38
0
 /// <summary>
 ///   Creates <c>GraphicsPath</c> for cylinder surface section. This 
 ///   path consists of two arcs and two vertical lines.
 /// </summary>
 /// <param name="startAngle">
 ///   Starting angle of the surface.
 /// </param>
 /// <param name="endAngle">
 ///   Ending angle of the surface.
 /// </param>
 /// <param name="pointStart">
 ///   Starting point on the cylinder surface.
 /// </param>
 /// <param name="pointEnd">
 ///   Ending point on the cylinder surface.
 /// </param>
 /// <returns>
 ///   <c>GraphicsPath</c> object representing the cylinder surface.
 /// </returns>
 private GraphicsPath CreatePathForCylinderSurfaceSection(float startAngle, float endAngle, GpPointF pointStart, GpPointF pointEnd)
 {
     GraphicsPath path = new GraphicsPath();
     path.AddArc(m_boundingRectangle.X, m_boundingRectangle.Y, m_boundingRectangle.Width, m_boundingRectangle.Height,startAngle, endAngle - startAngle);
     path.AddLine(pointEnd.X, pointEnd.Y, pointEnd.X, pointEnd.Y + m_sliceHeight);
     path.AddArc(m_boundingRectangle.X, m_boundingRectangle.Y + m_sliceHeight, m_boundingRectangle.Width, m_boundingRectangle.Height, endAngle, startAngle - endAngle);
     path.AddLine(pointStart.X, pointStart.Y + m_sliceHeight, pointStart.X, pointStart.Y);
     return path;
 }
 public GraphicsPath GetValueRec()
 {
     GraphicsPath gp = new GraphicsPath();
     gp.AddArc((float)((.05f) * vm.Width), (float)((1f / 3f) * vm.Height), (float)(.90f) * vm.Width, (float)(1.2f) * vm.Height, -180f, 180f);
     gp.AddLine((float)((.05f) * vm.Width), (float)((70f / 75f) * vm.Height), (float)(.95f) * vm.Width, (float)((70f / 75f) * vm.Height));
     return gp;
 }
Esempio n. 40
0
        protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
        {
            Graphics       g    = e.Graphics;
            TabStrip       tabs = e.ToolStrip as TabStrip;
            TabStripButton tab  = e.Item as TabStripButton;

            if (tabs == null || tab == null)
            {
                if (currentRenderer != null)
                {
                    currentRenderer.DrawButtonBackground(e);
                }
                else
                {
                    base.OnRenderButtonBackground(e);
                }
                return;
            }

            bool      selected = tab.Checked;
            bool      hovered  = tab.Selected;
            int       top      = 0;
            int       left     = 0;
            int       width    = tab.Bounds.Width - 1;
            int       height   = tab.Bounds.Height - 1;
            Rectangle drawBorder;


            if (UseVS)
            {
                if (tabs.Orientation == Orientation.Horizontal)
                {
                    if (!selected)
                    {
                        top     = selOffset;
                        height -= (selOffset - 1);
                    }
                    else
                    {
                        top = 1;
                    }
                    drawBorder = new Rectangle(0, 0, width, height);
                }
                else
                {
                    if (!selected)
                    {
                        left   = selOffset;
                        width -= (selOffset - 1);
                    }
                    else
                    {
                        left = 1;
                    }
                    drawBorder = new Rectangle(0, 0, height, width);
                }
                using (Bitmap b = new Bitmap(drawBorder.Width, drawBorder.Height))
                {
                    VisualStyleElement el = VisualStyleElement.Tab.TabItem.Normal;
                    if (selected)
                    {
                        el = VisualStyleElement.Tab.TabItem.Pressed;
                    }
                    if (hovered)
                    {
                        el = VisualStyleElement.Tab.TabItem.Hot;
                    }
                    if (!tab.Enabled)
                    {
                        el = VisualStyleElement.Tab.TabItem.Disabled;
                    }

                    if (!selected || hovered)
                    {
                        drawBorder.Width++;
                    }
                    else
                    {
                        drawBorder.Height++;
                    }

                    using (Graphics gr = Graphics.FromImage(b))
                    {
                        VisualStyleRenderer rndr = new VisualStyleRenderer(el);
                        rndr.DrawBackground(gr, drawBorder);

                        if (tabs.Orientation == Orientation.Vertical)
                        {
                            if (Mirrored)
                            {
                                b.RotateFlip(RotateFlipType.Rotate270FlipXY);
                            }
                            else
                            {
                                b.RotateFlip(RotateFlipType.Rotate270FlipNone);
                            }
                        }
                        else
                        {
                            if (Mirrored)
                            {
                                b.RotateFlip(RotateFlipType.RotateNoneFlipY);
                            }
                        }
                        if (Mirrored)
                        {
                            left = tab.Bounds.Width - b.Width - left;
                            top  = tab.Bounds.Height - b.Height - top;
                        }
                        g.DrawImage(b, left, top);
                    }
                }
            }
            else
            {
                if (tabs.Orientation == Orientation.Horizontal)
                {
                    if (!selected)
                    {
                        top     = selOffset;
                        height -= (selOffset - 1);
                    }
                    else
                    {
                        top = 1;
                    }
                    if (Mirrored)
                    {
                        left = 1;
                        top  = 0;
                    }
                    else
                    {
                        top++;
                    }
                    width--;
                }
                else
                {
                    if (!selected)
                    {
                        left = selOffset;
                        width--;
                    }
                    else
                    {
                        left = 1;
                    }
                    if (Mirrored)
                    {
                        left = 0;
                        top  = 1;
                    }
                }
                height--;
                drawBorder = new Rectangle(left, top, width, height);

                using (GraphicsPath gp = new GraphicsPath())
                {
                    if (Mirrored && tabs.Orientation == Orientation.Horizontal)
                    {
                        gp.AddLine(drawBorder.Left, drawBorder.Top, drawBorder.Left, drawBorder.Bottom - 2);
                        gp.AddArc(drawBorder.Left, drawBorder.Bottom - 3, 2, 2, 90, 90);
                        gp.AddLine(drawBorder.Left + 2, drawBorder.Bottom, drawBorder.Right - 2, drawBorder.Bottom);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Bottom - 3, 2, 2, 0, 90);
                        gp.AddLine(drawBorder.Right, drawBorder.Bottom - 2, drawBorder.Right, drawBorder.Top);
                    }
                    else if (!Mirrored && tabs.Orientation == Orientation.Horizontal)
                    {
                        gp.AddLine(drawBorder.Left, drawBorder.Bottom, drawBorder.Left, drawBorder.Top + 2);
                        gp.AddArc(drawBorder.Left, drawBorder.Top + 1, 2, 2, 180, 90);
                        gp.AddLine(drawBorder.Left + 2, drawBorder.Top, drawBorder.Right - 2, drawBorder.Top);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Top + 1, 2, 2, 270, 90);
                        gp.AddLine(drawBorder.Right, drawBorder.Top + 2, drawBorder.Right, drawBorder.Bottom);
                    }
                    else if (Mirrored && tabs.Orientation == Orientation.Vertical)
                    {
                        gp.AddLine(drawBorder.Left, drawBorder.Top, drawBorder.Right - 2, drawBorder.Top);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Top + 1, 2, 2, 270, 90);
                        gp.AddLine(drawBorder.Right, drawBorder.Top + 2, drawBorder.Right, drawBorder.Bottom - 2);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Bottom - 3, 2, 2, 0, 90);
                        gp.AddLine(drawBorder.Right - 2, drawBorder.Bottom, drawBorder.Left, drawBorder.Bottom);
                    }
                    else
                    {
                        gp.AddLine(drawBorder.Right, drawBorder.Top, drawBorder.Left + 2, drawBorder.Top);
                        gp.AddArc(drawBorder.Left, drawBorder.Top + 1, 2, 2, 180, 90);
                        gp.AddLine(drawBorder.Left, drawBorder.Top + 2, drawBorder.Left, drawBorder.Bottom - 2);
                        gp.AddArc(drawBorder.Left, drawBorder.Bottom - 3, 2, 2, 90, 90);
                        gp.AddLine(drawBorder.Left + 2, drawBorder.Bottom, drawBorder.Right, drawBorder.Bottom);
                    }

                    if (selected || hovered)
                    {
                        Color fill = (hovered) ? Color.WhiteSmoke : Color.White;
                        if (renderMode == ToolStripRenderMode.Professional)
                        {
                            fill = (hovered) ? ProfessionalColors.ButtonCheckedGradientBegin : ProfessionalColors.ButtonCheckedGradientEnd;
                            using (LinearGradientBrush br = new LinearGradientBrush(tab.ContentRectangle, fill, ProfessionalColors.ButtonCheckedGradientMiddle, LinearGradientMode.Vertical))
                                g.FillPath(br, gp);
                        }
                        else
                        {
                            using (SolidBrush br = new SolidBrush(fill))
                                g.FillPath(br, gp);
                        }
                    }
                    using (Pen p = new Pen((selected) ? ControlPaint.Dark(SystemColors.AppWorkspace) : SystemColors.AppWorkspace))
                        g.DrawPath(p, gp);
                }
            }
        }
Esempio n. 41
0
        /// <summary>
        /// Draws rounded rectangle on the board(graph object)
        /// </summary>
        /// <param name="graphObj">Graph Object(board) to drawn on</param>
        /// <param name="dx">X region on board</param>
        /// <param name="dy">Y region on board</param>
        /// <param name="zoom">Zoom value</param>
        public override void Draw(Graphics graphObj, int dx, int dy, float zoom)
        {
            float n       = this.arcsWidth;
            Brush myBrush = GetBrush(dx, dy, zoom);
            Pen   myPen   = this.CreatePen(zoom);

            // Create a path and add the object.
            GraphicsPath myPath = new GraphicsPath();

            myPath.AddArc(new RectangleF((region.X0 + dx) * zoom, (region.Y0 + dy) * zoom, n * zoom, n * zoom), 180, 90);
            myPath.AddLine((region.X0 + dx + n / 2) * zoom, (region.Y0 + dy) * zoom, (region.X1 + dx - n / 2) * zoom, (region.Y0 + dy) * zoom);

            myPath.AddArc(new RectangleF((region.X1 + dx - n) * zoom, (region.Y0 + dy) * zoom, n * zoom, n * zoom), 270, 90);
            myPath.AddLine((region.X1 + dx) * zoom, (region.Y0 + dy + n / 2) * zoom, (region.X1 + dx) * zoom, (region.Y1 + dy - n / 2) * zoom);

            myPath.AddArc(new RectangleF((region.X1 + dx - n) * zoom, (region.Y1 + dy - n) * zoom, n * zoom, n * zoom), 0, 90);
            myPath.AddLine((region.X0 + dx + n / 2) * zoom, (region.Y1 + dy) * zoom, (region.X1 + dx - n / 2) * zoom, (region.Y1 + dy) * zoom);

            myPath.AddArc(new RectangleF((region.X0 + dx) * zoom, (region.Y1 + dy - n) * zoom, n * zoom, n * zoom), 90, 90);
            myPath.AddLine((region.X0 + dx) * zoom, (region.Y1 + dy - n / 2) * zoom, (region.X0 + dx) * zoom, (region.Y0 + dy + n / 2) * zoom);

            if (this.generateCornerNames)
            {
                myPath.AddString("A", SystemFonts.CaptionFont.FontFamily,
                                 (int)SystemFonts.CaptionFont.Style, 12, new Point(this.region.X0 - 15,
                                                                                   this.region.Y0 - 15), StringFormat.GenericDefault);
                myPath.AddString("B", SystemFonts.CaptionFont.FontFamily,
                                 (int)SystemFonts.CaptionFont.Style, 12, new Point(this.region.X1 + 5,
                                                                                   this.region.Y0 - 15), StringFormat.GenericDefault);
                myPath.AddString("C", SystemFonts.CaptionFont.FontFamily,
                                 (int)SystemFonts.CaptionFont.Style, 12, new Point(this.region.X1 + 5,
                                                                                   this.region.Y1 + 5), StringFormat.GenericDefault);
                myPath.AddString("D", SystemFonts.CaptionFont.FontFamily,
                                 (int)SystemFonts.CaptionFont.Style, 12, new Point(this.region.X0 - 15,
                                                                                   this.region.Y1 + 5), StringFormat.GenericDefault);
            }
            Matrix translateMatrix = new Matrix();

            translateMatrix.RotateAt(this.Rotation, new PointF((region.X0 + dx + (int)(region.X1 - region.X0) / 2) * zoom, (region.Y0 + dy + (int)(region.Y1 - region.Y0) / 2) * zoom));
            myPath.Transform(translateMatrix);

            // Draw the transformed ellipse to the screen.
            if (this.FillEnabled)
            {
                graphObj.FillPath(myBrush, myPath);
                if (this.ShowBorder)
                {
                    graphObj.DrawPath(myPen, myPath);
                }
            }
            else
            {
                graphObj.DrawPath(myPen, myPath);
            }

            myPath.Dispose();
            myPen.Dispose();
            if (myBrush != null)
            {
                myBrush.Dispose();
            }
        }
Esempio n. 42
0
        private GraphicsPath TracePath(Cell startCell, Cell endCell)
        {
            var  path    = new GraphicsPath();
            bool bending = false; // Jon Snow.
            var  a       = endCell;

            while (a != startCell && a.Parent is Cell b)
            {
                var aDir = a.Direction.Scale(-1);
                var bDir = b.Direction.Scale(-1);
                var aLoc = a.Location;
                var bLoc = b.Location;
                var cLoc = b.Location.Translate(bDir.Row, bDir.Col);
                var rect = new Rectangle(
                    PageRenderOptions.GridSize * Math.Min(aLoc.Col, Math.Min(bLoc.Col, cLoc.Col)),
                    PageRenderOptions.GridSize * Math.Min(aLoc.Row, Math.Min(bLoc.Row, cLoc.Row)),
                    PageRenderOptions.GridSize * 1,
                    PageRenderOptions.GridSize * 1);
                if (aDir == bDir)
                {
                    if (bending)
                    {
                        bending = false;
                    }
                }
                else
                {
                    bending = true;
                    if (aDir == Cell.MoveUp && bDir == Cell.MoveLeft)
                    {
                        // c b
                        //   a
                        path.AddArc(rect, 0, -90);
                    }
                    else if (aDir == Cell.MoveUp && bDir == Cell.MoveRight)
                    {
                        // b c
                        // a
                        path.AddArc(rect, 180, 90);
                    }
                    else if (aDir == Cell.MoveDown && bDir == Cell.MoveLeft)
                    {
                        //   a
                        // c b
                        path.AddArc(rect, 0, 90);
                    }
                    else if (aDir == Cell.MoveDown && bDir == Cell.MoveRight)
                    {
                        // a
                        // b c
                        path.AddArc(rect, 180, -90);
                    }
                    else if (aDir == Cell.MoveLeft && bDir == Cell.MoveUp)
                    {
                        // c
                        // b a
                        path.AddArc(rect, 90, 90);
                    }
                    else if (aDir == Cell.MoveLeft && bDir == Cell.MoveDown)
                    {
                        // b a
                        // c
                        path.AddArc(rect, -90, -90);
                    }
                    else if (aDir == Cell.MoveRight && bDir == Cell.MoveUp)
                    {
                        //   c
                        // a b
                        path.AddArc(rect, 90, -90);
                    }
                    else if (aDir == Cell.MoveRight && bDir == Cell.MoveDown)
                    {
                        // a b
                        //   c
                        path.AddArc(rect, -90, 90);
                    }
                }
                a = b;
            }

            return(path);
        }
            private Region CreateRoundedRectangleRegion(int radius, Rectangle rectangle)
            {
                using (GraphicsPath Path = new GraphicsPath())
                {
                    int Radius2 = (radius * 2);

                    Path.FillMode = FillMode.Winding;

                    Path.StartFigure();
                    Path.AddArc(rectangle.X, rectangle.Y, Radius2, Radius2, 180, 90);
                    Path.AddLine(rectangle.X + radius, rectangle.Y, rectangle.Right - radius, rectangle.Y);
                    Path.AddArc(rectangle.Right - Radius2 - 1, rectangle.Y, Radius2, Radius2, 270, 90);
                    Path.AddLine(rectangle.Right, rectangle.Y + radius, rectangle.Right, rectangle.Bottom - radius);
                    Path.AddArc(rectangle.Right - Radius2 - 1, rectangle.Bottom - Radius2 - 1, Radius2, Radius2, 0, 90);
                    Path.AddLine(rectangle.Right - radius, rectangle.Bottom, rectangle.X + radius, rectangle.Bottom);
                    Path.AddArc(rectangle.X, rectangle.Bottom - Radius2 - 1, Radius2, Radius2, 90, 90);
                    Path.AddLine(rectangle.X, rectangle.Bottom - radius, rectangle.X, rectangle.Y + radius);
                    Path.CloseFigure();

                    return new Region(Path);
                }
            }
Esempio n. 44
0
 internal GraphicsPath CreateRoundRect(Rectangle r, int curve)
 {
     // Draw a border radius
     try
     {
         CreateRoundPath = new GraphicsPath(FillMode.Winding);
         CreateRoundPath.AddArc(r.X, r.Y, curve, curve, 180f, 90f);
         CreateRoundPath.AddArc(r.Right - curve, r.Y, curve, curve, 270f, 90f);
         CreateRoundPath.AddArc(r.Right - curve, r.Bottom - curve, curve, curve, 0f, 90f);
         CreateRoundPath.AddArc(r.X, r.Bottom - curve, curve, curve, 90f, 90f);
         CreateRoundPath.CloseFigure();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + Environment.NewLine + Environment.NewLine + "Value must be either '1' or higher", "Invalid Integer", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         // Return to the default border curve if the parameter is less than "1"
         _BorderCurve = 8;
         BorderCurve = 8;
     }
     return CreateRoundPath;
 }
Esempio n. 45
0
 public static GraphicsPath RoundRect(Rectangle rect, int slope)
 {
     GraphicsPath gp = new GraphicsPath();
     int arcWidth = slope * 2;
     gp.AddArc(new Rectangle(rect.X, rect.Y, arcWidth, arcWidth), -180, 90);
     gp.AddArc(new Rectangle(rect.Width - arcWidth + rect.X, rect.Y, arcWidth, arcWidth), -90, 90);
     gp.AddArc(new Rectangle(rect.Width - arcWidth + rect.X, rect.Height - arcWidth + rect.Y, arcWidth, arcWidth), 0, 90);
     gp.AddArc(new Rectangle(rect.X, rect.Height - arcWidth + rect.Y, arcWidth, arcWidth), 90, 90);
     gp.CloseAllFigures();
     return gp;
 }
Esempio n. 46
0
        public static GraphicsPath CreatePath(
            RectangleF rect,
            int cornerRadius,
            int margin,
            CornerType corners
            )
        {
            GraphicsPath graphicsPath = new GraphicsPath();

            float xOffset  = rect.X + margin;
            float yOffset  = rect.Y + margin;
            float xExtent  = rect.X + rect.Width - margin;
            float yExtent  = rect.Y + rect.Height - margin;
            int   diameter = cornerRadius << 1;

            // top arc
            if ((corners & CornerType.TopLeft) != 0)
            {
                graphicsPath.AddArc(new RectangleF(xOffset, yOffset, diameter, diameter), 180, 90);
            }
            else
            {
                graphicsPath.AddLine(new PointF(xOffset, yOffset + cornerRadius), new PointF(xOffset, yOffset));
                graphicsPath.AddLine(new PointF(xOffset, yOffset), new PointF(xOffset + cornerRadius, yOffset));
            }

            // top line
            graphicsPath.AddLine(new PointF(xOffset + cornerRadius, yOffset), new PointF(xExtent - cornerRadius, yOffset));

            // top right arc
            if ((corners & CornerType.TopRight) != 0)
            {
                graphicsPath.AddArc(new RectangleF(xExtent - diameter, yOffset, diameter, diameter), 270, 90);
            }
            else
            {
                graphicsPath.AddLine(new PointF(xExtent - cornerRadius, yOffset), new PointF(xExtent, yOffset));
                graphicsPath.AddLine(new PointF(xExtent, yOffset), new PointF(xExtent, yOffset + cornerRadius));
            }

            // right line
            graphicsPath.AddLine(new PointF(xExtent, yOffset + cornerRadius), new PointF(xExtent, yExtent - cornerRadius));

            // bottom right arc
            if ((corners & CornerType.BottomRight) != 0)
            {
                graphicsPath.AddArc(new RectangleF(xExtent - diameter, yExtent - diameter, diameter, diameter), 0, 90);
            }
            else
            {
                graphicsPath.AddLine(new PointF(xExtent, yExtent - cornerRadius), new PointF(xExtent, yExtent));
                graphicsPath.AddLine(new PointF(xExtent, yExtent), new PointF(xExtent - cornerRadius, yExtent));
            }

            // bottom line
            graphicsPath.AddLine(new PointF(xExtent - cornerRadius, yExtent), new PointF(xOffset + cornerRadius, yExtent));

            // bottom left arc
            if ((corners & CornerType.BottomLeft) != 0)
            {
                graphicsPath.AddArc(new RectangleF(xOffset, yExtent - diameter, diameter, diameter), 90, 90);
            }
            else
            {
                graphicsPath.AddLine(new PointF(xOffset + cornerRadius, yExtent), new PointF(xOffset, yExtent));
                graphicsPath.AddLine(new PointF(xOffset, yExtent), new PointF(xOffset, yExtent - cornerRadius));
            }


            // left line
            graphicsPath.AddLine(new PointF(xOffset, yExtent - cornerRadius), new PointF(xOffset, yOffset + cornerRadius));

            graphicsPath.CloseFigure();
            return(graphicsPath);
        }
Esempio n. 47
0
	protected GraphicsPath GetPath()
	{
		GraphicsPath graphPath = new GraphicsPath();

		if (_BorderStyle == BorderStyle.Fixed3D)
		{
			graphPath.AddRectangle(ClientRectangle);
		}
		else
		{
			try
			{
				int curve = 0;

				Rectangle rect = ClientRectangle;
				int offset = 0;

				switch (_BorderStyle)
				{
				case BorderStyle.FixedSingle:
					offset = (int) Math.Ceiling(BorderWidth / 2.0d);
					curve = adjustedCurve;

					break;
				case BorderStyle.Fixed3D:

					break;
				case BorderStyle.None:
					curve = adjustedCurve;

					break;
				}

				if (curve == 0)
				{
					graphPath.AddRectangle(Rectangle.Inflate(rect, -offset, -offset));
				}
				else
				{
					int rectWidth = rect.Width - 1 - offset;
					int rectHeight = rect.Height - 1 - offset;
					int curveWidth;

					if ((_CurveMode & CornerCurveMode.TopRight) != 0)
					{
						curveWidth = (curve * 2);
					}
					else
					{
						curveWidth = 1;
					}
					graphPath.AddArc(rectWidth - curveWidth, offset, curveWidth, curveWidth, 270, 90);

					if ((_CurveMode & CornerCurveMode.BottomRight) != 0)
					{
						curveWidth = (curve * 2);
					}
					else
					{
						curveWidth = 1;
					}
					graphPath.AddArc(rectWidth - curveWidth, rectHeight - curveWidth, curveWidth, curveWidth, 0, 90);

					if ((_CurveMode & CornerCurveMode.BottomLeft) != 0)
					{
						curveWidth = (curve * 2);
					}
					else
					{
						curveWidth = 1;
					}
					graphPath.AddArc(offset, rectHeight - curveWidth, curveWidth, curveWidth, 90, 90);

					if ((_CurveMode & CornerCurveMode.TopLeft) != 0)
					{
						curveWidth = (curve * 2);
					}
					else
					{
						curveWidth = 1;
					}
					graphPath.AddArc(offset, offset, curveWidth, curveWidth, 180, 90);

					graphPath.CloseFigure();
				}
			}
			catch (Exception)
			{
				graphPath.AddRectangle(ClientRectangle);
			}
		}

		return graphPath;
	}
Esempio n. 48
0
    private static Image MakeRoundedCorners(Image image, int radius)
    {
        Bitmap bmp = new Bitmap(image, image.Width, image.Height);
        using (Graphics g = Graphics.FromImage(bmp))
        {
            Brush brush = new SolidBrush(Color.White);

            for (int i = 0; i < 4; i++)
            {
                Point[] cornerUpLeft = new Point[3];

                cornerUpLeft[0].X = 0;
                cornerUpLeft[0].Y = 0;

                cornerUpLeft[1].X = radius;
                cornerUpLeft[1].Y = 0;

                cornerUpLeft[2].X = 0;
                cornerUpLeft[2].Y = radius;

                GraphicsPath pathCornerUpLeft = new GraphicsPath();

                pathCornerUpLeft.AddArc(cornerUpLeft[0].X, cornerUpLeft[0].Y,
                                        radius, radius, 180, 90);
                pathCornerUpLeft.AddLine(cornerUpLeft[0].X, cornerUpLeft[0].Y,
                                         cornerUpLeft[1].X, cornerUpLeft[1].Y);
                pathCornerUpLeft.AddLine(cornerUpLeft[0].X, cornerUpLeft[0].Y,
                                         cornerUpLeft[2].X, cornerUpLeft[2].Y);

                g.FillPath(brush, pathCornerUpLeft);
                pathCornerUpLeft.Dispose();

                bmp.RotateFlip(RotateFlipType.Rotate90FlipNone);
            }

            brush.Dispose();
            g.Dispose();
        }
        return bmp;
    }
Esempio n. 49
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics  g      = e.Graphics;
            Rectangle bounds = this.ClientRectangle;

            bounds.Offset(1, 1);
            bounds.Inflate(-2, -2);
            Color startColor = SystemColors.ControlLightLight;
            Color endColor   = SystemColors.Control;

            if (selected)
            {
                startColor = Mix(SystemColors.ControlLightLight, SystemColors.Highlight, 0.1);
                endColor   = Mix(SystemColors.ControlLightLight, SystemColors.Highlight, 0.65);
            }
            Brush gradient = new LinearGradientBrush(bounds,
                                                     startColor,
                                                     endColor,
                                                     LinearGradientMode.ForwardDiagonal);

            GraphicsPath path = new GraphicsPath();

            const int egdeRadius  = 3;
            const int innerMargin = egdeRadius + 2;

            RectangleF arcRect = new RectangleF(bounds.Location, new SizeF(egdeRadius * 2, egdeRadius * 2));

            //top left Arc
            path.AddArc(arcRect, 180, 90);
            path.AddLine(bounds.X + egdeRadius, bounds.Y, bounds.Right - egdeRadius, bounds.Y);
            // top right arc
            arcRect.X = bounds.Right - egdeRadius * 2;
            path.AddArc(arcRect, 270, 90);
            path.AddLine(bounds.Right, bounds.Left + egdeRadius, bounds.Right, bounds.Bottom - egdeRadius);
            // bottom right arc
            arcRect.Y = bounds.Bottom - egdeRadius * 2;
            path.AddArc(arcRect, 0, 90);
            path.AddLine(bounds.X + egdeRadius, bounds.Bottom, bounds.Right - egdeRadius, bounds.Bottom);
            // bottom left arc
            arcRect.X = bounds.Left;
            path.AddArc(arcRect, 90, 90);
            path.AddLine(bounds.X, bounds.Left + egdeRadius, bounds.X, bounds.Bottom - egdeRadius);

            g.FillPath(gradient, path);
            g.DrawPath(SystemPens.ControlText, path);
            path.Dispose();
            gradient.Dispose();
            Brush  textBrush;
            string description = GetText(out textBrush);
            int    titleWidth;

            using (Font boldFont = new Font("Arial", 8, FontStyle.Bold)) {
                g.DrawString(addIn.Name, boldFont, textBrush, innerMargin, innerMargin);
                titleWidth = (int)g.MeasureString(addIn.Name, boldFont).Width + 1;
            }
            if (addIn.Version != null && addIn.Version.ToString() != "0.0.0.0")
            {
                g.DrawString(addIn.Version.ToString(), Font, textBrush, innerMargin + titleWidth + 4, innerMargin);
            }
            RectangleF textBounds = bounds;

            textBounds.Offset(innerMargin, innerMargin);
            textBounds.Inflate(-innerMargin * 2, -innerMargin * 2 + 2);
            if (isExternal)
            {
                textBounds.Height -= pathHeight;
            }
            using (StringFormat sf = new StringFormat(StringFormatFlags.LineLimit)) {
                sf.Trimming = StringTrimming.EllipsisWord;
                g.DrawString(description, Font, textBrush, textBounds, sf);
            }
            if (isExternal)
            {
                textBounds.Y      = textBounds.Bottom + 2;
                textBounds.Height = pathHeight + 2;
                using (Font font = new Font(Font.Name, 7, FontStyle.Italic)) {
                    using (StringFormat sf = new StringFormat(StringFormatFlags.NoWrap)) {
                        sf.Trimming  = StringTrimming.EllipsisPath;
                        sf.Alignment = StringAlignment.Far;
                        g.DrawString(addIn.FileName, font,
                                     selected ? SystemBrushes.HighlightText : SystemBrushes.ControlText,
                                     textBounds, sf);
                    }
                }
            }
        }
Esempio n. 50
0
        private GraphicsPath BuildMenuIconShape(ref Rectangle rcMenuIcon)
        {
            GraphicsPath XMenuIconPath = new GraphicsPath();

            switch (m_xTitleBar.TitleBarType)
            {
            case XTitleBar.XTitleBarType.Rounded:
                XMenuIconPath.AddArc(
                    rcMenuIcon.Left,
                    rcMenuIcon.Top,
                    rcMenuIcon.Height,
                    rcMenuIcon.Height,
                    90,
                    180);
                XMenuIconPath.AddLine(
                    rcMenuIcon.Left + rcMenuIcon.Height / 2,
                    rcMenuIcon.Top,
                    rcMenuIcon.Right,
                    rcMenuIcon.Top
                    );
                XMenuIconPath.AddBezier(
                    new Point(rcMenuIcon.Right, rcMenuIcon.Top),
                    new Point(rcMenuIcon.Right - 10, rcMenuIcon.Bottom / 2 - 5),
                    new Point(rcMenuIcon.Right - 12, rcMenuIcon.Bottom / 2 + 5),
                    new Point(rcMenuIcon.Right, rcMenuIcon.Bottom)
                    );
                XMenuIconPath.AddLine(
                    rcMenuIcon.Right,
                    rcMenuIcon.Bottom,
                    rcMenuIcon.Left + rcMenuIcon.Height / 2,
                    rcMenuIcon.Bottom
                    );
                break;

            case XTitleBar.XTitleBarType.Angular:
                XMenuIconPath.AddArc(
                    rcMenuIcon.Left,
                    rcMenuIcon.Top,
                    rcMenuIcon.Height,
                    rcMenuIcon.Height,
                    90,
                    180);
                XMenuIconPath.AddLine(
                    rcMenuIcon.Left + rcMenuIcon.Height / 2,
                    rcMenuIcon.Top,
                    rcMenuIcon.Right + 18,
                    rcMenuIcon.Top
                    );
                XMenuIconPath.AddLine(
                    rcMenuIcon.Right + 18,
                    rcMenuIcon.Top,
                    rcMenuIcon.Right - 5,
                    rcMenuIcon.Bottom
                    );
                XMenuIconPath.AddLine(
                    rcMenuIcon.Right - 5,
                    rcMenuIcon.Bottom,
                    rcMenuIcon.Left + rcMenuIcon.Height / 2,
                    rcMenuIcon.Bottom
                    );
                break;

            case XTitleBar.XTitleBarType.Rectangular:
                XMenuIconPath.AddArc(
                    rcMenuIcon.Left,
                    rcMenuIcon.Top,
                    rcMenuIcon.Height,
                    rcMenuIcon.Height,
                    90,
                    180);
                XMenuIconPath.AddLine(
                    rcMenuIcon.Left + rcMenuIcon.Height / 2,
                    rcMenuIcon.Top,
                    rcMenuIcon.Right,
                    rcMenuIcon.Top
                    );
                XMenuIconPath.AddLine(
                    rcMenuIcon.Right,
                    rcMenuIcon.Top,
                    rcMenuIcon.Right,
                    rcMenuIcon.Bottom
                    );
                XMenuIconPath.AddLine(
                    rcMenuIcon.Right,
                    rcMenuIcon.Bottom,
                    rcMenuIcon.Left + rcMenuIcon.Height / 2,
                    rcMenuIcon.Bottom
                    );
                break;
            }
            return(XMenuIconPath);
        }
Esempio n. 51
0
                public static void RoundedRect(Graphics aGraph, Rectangle aRect, int aR, Pen aPen, Brush aBrush)
                {
                    // First, build path:
                    GraphicsPath lPath = new GraphicsPath();

                    lPath.StartFigure();
                    lPath.AddArc(aRect.Left, aRect.Top, aR, aR, 180, 90);
                    lPath.AddArc(aRect.Left + aRect.Width - aR, aRect.Top, aR, aR, 270, 90);
                    lPath.AddArc(aRect.Left + aRect.Width - aR, aRect.Top + aRect.Height - aR, aR, aR, 0, 90);
                    lPath.AddArc(aRect.Left + 0, aRect.Top + aRect.Height - aR, aR, aR, 90, 90);
                    lPath.CloseFigure();

                    if (aBrush != null)
                        aGraph.FillPath(aBrush, lPath);

                    if (aPen != null)
                        aGraph.DrawPath(aPen, lPath);
                }