示例#1
0
        //捺(不带横)
        private void DrawNa_n(Graphics g)
        {
            SolidBrush   brush = new SolidBrush(Color.Black);
            GraphicsPath path  = new GraphicsPath();

            double k    = Math.Atan((points[0].X - points[2].X) / (points[2].Y - points[0].Y)); //计算点的总体斜角
            float  sink = (float)Math.Sin(k);
            float  cosk = (float)Math.Cos(k);

            PointF[] pointCurve1 = new PointF[3];   //右边曲线
            pointCurve1[0] = new PointF(points[0].X + widththin / 2, points[0].Y);
            pointCurve1[1] = new PointF(points[1].X + widththick / 2 * 0.8f * cosk, points[1].Y + widththick / 2 * 0.8f * sink);
            pointCurve1[2] = new PointF(points[2].X + widththick * 1.2f, points[2].Y - widththick * 0.4f);
            path.AddCurve(pointCurve1, 0.6f);

            PointF[] pointCurve2 = new PointF[3];   //下方曲线
            pointCurve2[0] = new PointF(pointCurve1[2].X, pointCurve1[2].Y + widththin / 2);
            pointCurve2[1] = points[2];
            pointCurve2[2] = new PointF(points[2].X - widththick * 0.5f, points[2].Y + widththick * 0.5f);
            path.AddCurve(pointCurve2, 0.7f);

            PointF[] pointCurve3 = new PointF[3];   //左边曲线
            pointCurve3[0] = pointCurve2[2];
            pointCurve3[1] = new PointF(points[1].X - widththick / 2 * 0.8f * cosk, points[1].Y - widththick / 2 * 0.8f * sink);
            pointCurve3[2] = new PointF(points[0].X - widththin * 0.5f, points[0].Y);
            path.AddCurve(pointCurve3);

            g.FillPath(brush, path);
            path.Dispose();
            brush.Dispose();
        }
示例#2
0
        private GraphicsPath CollectPath(Edge e, List <Edge> edges)
        {
            var p = new GraphicsPath();

            var currentEdge = e;

            edges.Remove(currentEdge);
            p.AddCurve(e.Points);

            while (currentEdge == e || (e.Start != currentEdge.End && e.Start != currentEdge.Start))
            {
                bool reverse  = false;
                var  nextEdge = currentEdge.EndCorner.Edges.Find(ed => ed != currentEdge && ed.Coast);

                if (!edges.Contains(nextEdge))
                {
                    nextEdge = currentEdge.StartCorner.Edges.Find(ed => ed != currentEdge && ed.Coast);
                    reverse  = true;
                }

                currentEdge = nextEdge;

                edges.Remove(currentEdge);
                p.AddCurve(reverse ? currentEdge.Points.Reverse().Skip(1).ToArray() : currentEdge.Points.Skip(1).ToArray());
            }

            return(p);
        }
示例#3
0
        //点提(三点水的提)
        private void DrawDianti(Graphics g)
        {
            double k    = Math.Atan((points[6].X - points[5].X) / (points[5].Y - points[6].Y)); //计算提的斜角
            float  sink = (float)Math.Sin(k);
            float  cosk = (float)Math.Cos(k);

            PointF[] pointCurve = new PointF[7];
            pointCurve[0] = points[0];
            pointCurve[1] = points[1];
            pointCurve[2] = points[2];
            pointCurve[3] = points[3];
            pointCurve[4] = points[4];
            pointCurve[5] = points[5];
            pointCurve[6] = points[6];

            PointF[] pointCurve2 = new PointF[3];

            float w = points[5].X - points[1].X;

            pointCurve2[0] = new PointF(points[6].X - widththin / 2 * cosk, points[6].Y - widththin / 2 * sink);
            pointCurve2[1] = new PointF(points[5].X - w * cosk, points[5].Y - w * sink);
            pointCurve2[2] = new PointF(points[0].X, points[0].Y - widththin / 2);

            SolidBrush   brush = new SolidBrush(Color.Black);
            GraphicsPath path  = new GraphicsPath();

            //按轮廓顺序加入
            path.AddCurve(pointCurve, 0.5f);
            path.AddCurve(pointCurve2, 0.2f);
            g.FillPath(brush, path);
            path.Dispose();
            brush.Dispose();
        }
示例#4
0
        //横折
        private void DrawHengzhe(Graphics g)
        {
            PointF[] pointDraw = new PointF[3]; //横的一段
            pointDraw[0] = new PointF(points[1].X - widththick, points[1].Y);
            pointDraw[1] = new PointF(points[0].X + widththin * 2, points[0].Y);
            pointDraw[2] = new PointF(points[0].X, points[0].Y + widththin / 4);

            PointF[] pointline = new PointF[2]; //横的一段
            pointline[0] = new PointF(points[0].X - widththin, points[0].Y - widththin);
            pointline[1] = new PointF(pointDraw[0].X - widththin / 2, pointDraw[0].Y - widththin);

            PointF[] pointcurve1 = new PointF[4];   //弯头
            pointcurve1[0] = pointline[1];
            pointcurve1[1] = new PointF(pointcurve1[0].X + widththick / 2, pointcurve1[0].Y - widththick / 2);
            pointcurve1[2] = new PointF(points[1].X + widththin, points[1].Y);
            pointcurve1[3] = new PointF(points[1].X, points[1].Y + widththin * (float)Math.Cos(Math.PI / 6));

            PointF[] pointDraw1 = new PointF[4]; //竖由6个点相互连接的线段组成
            pointDraw1[0] = pointcurve1[3];
            pointDraw1[1] = new PointF(points[2].X, points[2].Y - widththick * (float)Math.Sin(Math.PI / 12));
            pointDraw1[2] = new PointF(points[2].X - widththick, points[2].Y);
            pointDraw1[3] = pointDraw[0];

            SolidBrush   brush = new SolidBrush(Color.Black);
            GraphicsPath path  = new GraphicsPath();

            //按轮廓顺序加入
            path.AddCurve(pointDraw);
            path.AddLines(pointline);
            path.AddCurve(pointcurve1);
            path.AddCurve(pointDraw1, 0.1f);
            g.FillPath(brush, path);
            path.Dispose();
            brush.Dispose();
        }
        /// <summary>
        /// Paints an pushed effect according the provided position ans style
        /// </summary>
        /// <param name="graphics">Graphics to paint into</param>
        /// <param name="width">Width of the control (for centering purposes)</param>
        /// <param name="height">Height of the control (for centering purposes)</param>
        internal static void PaintPushedEffect(Graphics graphics, int width, int height)
        {
            Pen          outerBorderPen  = new Pen(new SolidBrush(Color.FromArgb(120, Color.Gainsboro)));
            GraphicsPath outerBorderPath = new GraphicsPath();

            outerBorderPath.AddLine(new Point(3, height), new Point(3, 5));
            outerBorderPath.AddCurve(new Point[] { new Point(3, 5), new Point(5, 3) }, 0.5f);
            outerBorderPath.AddLine(new Point(5, 3), new Point(width - 6, 3));
            outerBorderPath.AddCurve(new Point[] { new Point(width - 6, 3), new Point(width - 4, 5) }, 0.5f);
            outerBorderPath.AddLine(new Point(width - 4, 5), new Point(width - 4, height));

            Pen          innerBorderPen  = new Pen(new SolidBrush(Color.FromArgb(120, Color.Black)));
            GraphicsPath innerBorderPath = new GraphicsPath();

            innerBorderPath.AddLine(new Point(4, height), new Point(4, 5));
            innerBorderPath.AddLine(new Point(5, 4), new Point(width - 6, 4));
            innerBorderPath.AddLine(new Point(width - 5, 5), new Point(width - 5, height));

            Pen          outerBorderButtonPen  = new Pen(new SolidBrush(Color.FromArgb(70, Color.Black)));
            GraphicsPath outerButtonBorderPath = new GraphicsPath();

            outerButtonBorderPath.AddLines(new Point[]
            {
                new Point(5, height),
                new Point(5, 5),
                new Point(width - 6, 5),
                new Point(width - 6, height)
            });

            graphics.DrawPath(outerBorderPen, outerBorderPath);
            graphics.DrawPath(innerBorderPen, innerBorderPath);
            graphics.DrawPath(outerBorderButtonPen, outerButtonBorderPath);
        }
        private GraphicsPath GetPath(int index)
        {
            GraphicsPath path = new GraphicsPath();
            Rectangle    rect = GetTabRect(index);

            if (index == SelectedIndex)
            {
                path.AddLine(rect.Left, rect.Bottom, rect.Left, rect.Top + 4);
                path.AddCurve(new[] { new Point(rect.Left, rect.Top + 4), new Point(rect.Left + 1, rect.Top + 2), new Point(rect.Left + 2, rect.Top + 1), new Point(rect.Left + 4, rect.Top) });
                path.AddLine(rect.Left + 4, rect.Top, rect.Right - 4, rect.Top);
                path.AddCurve(new[] { new Point(rect.Right - 4, rect.Top), new Point(rect.Right - 2, rect.Top + 1), new Point(rect.Right - 1, rect.Top + 2), new Point(rect.Right, rect.Top + 4) });
                path.AddLine(rect.Right, rect.Top + 4, rect.Right, rect.Bottom);
                path.AddLine(rect.Right, rect.Top, rect.Left, rect.Top);
            }
            else
            {
                path.AddLine(rect.Left, rect.Bottom, rect.Left, rect.Top + 6);
                path.AddCurve(new[] { new Point(rect.Left, rect.Top + 6), new Point(rect.Left + 1, rect.Top + 4), new Point(rect.Left + 2, rect.Top + 3), new Point(rect.Left + 4, rect.Top + 2) });
                path.AddLine(rect.Left + 4, rect.Top + 2, rect.Right - 4, rect.Top + 2);
                path.AddCurve(new[] { new Point(rect.Right - 4, rect.Top + 2), new Point(rect.Right - 2, rect.Top + 3), new Point(rect.Right - 1, rect.Top + 4), new Point(rect.Right, rect.Top + 6) });
                path.AddLine(rect.Right, rect.Top + 6, rect.Right, rect.Bottom);
                path.AddLine(rect.Right, rect.Top, rect.Left, rect.Top);
            }

            return(path);
        }
示例#7
0
        /// <summary>
        /// Override the normal drawing of the tabs
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="drawItemInfo">
        /// The draw item info.
        /// </param>
        private void TabControlAdv1DrawItem(object sender, DrawTabEventArgs drawItemInfo)
        {
            drawItemInfo.DrawBackground();
            drawItemInfo.DrawInterior();

            var rectTab = drawItemInfo.Bounds;
            var g       = drawItemInfo.Graphics;

            g.SmoothingMode = SmoothingMode.AntiAlias;

            // Create a path for the border
            var gp = new GraphicsPath();

            gp.AddBezier(
                rectTab.Right - 1,
                rectTab.Bottom + 6,
                rectTab.Right - 1,
                rectTab.Bottom + 2,
                rectTab.Left,
                rectTab.Bottom - 3,
                rectTab.Left,
                rectTab.Bottom - 7);
            gp.AddLine(rectTab.Left, rectTab.Bottom - 4, rectTab.Left, rectTab.Top + 5);

            Point[] curvePoints1 =
            {
                new Point(rectTab.Left,     rectTab.Top + 5),
                new Point(rectTab.Left + 2, rectTab.Top + 2),
                new Point(rectTab.Left + 3, rectTab.Top + 1),
                new Point(rectTab.Left + 5, rectTab.Top)
            };
            gp.AddCurve(curvePoints1);
            gp.AddBezier(curvePoints1[0], curvePoints1[1], curvePoints1[2], curvePoints1[3]);
            gp.AddLine(curvePoints1[3], new Point(rectTab.Right - 6, rectTab.Top));
            Point[] curvePoints2 =
            {
                new Point(rectTab.Right - 6, rectTab.Top),
                new Point(rectTab.Right - 2, rectTab.Top - 1),
                new Point(rectTab.Right - 2, rectTab.Top - 3),
                new Point(rectTab.Right - 1, rectTab.Top - 5)
            };
            gp.AddCurve(curvePoints2);

            if (((int)drawItemInfo.State & (int)DrawItemState.Selected) > 0)
            {
                g.FillPath(new SolidBrush(drawItemInfo.BackColor), gp);

                drawItemInfo.DrawInterior();
            }
            else
            {
                // Draw the Text and Image first
                drawItemInfo.DrawInterior();

                // Then alpha blend active tab color over it
                g.FillPath(new SolidBrush(Color.FromArgb(128, this.tabControlAdv1.ActiveTabColor)), gp);
            }
        }
示例#8
0
        private GraphicsPath GetGraphicsPath()
        {
            GraphicsPath path = new GraphicsPath();

            switch (_pencilType)
            {
            case enumPencilType.Circle:
                Rectangle rect = new Rectangle(Math.Min(_prePoint.X, _crtPoint.X),
                                               Math.Min(_prePoint.Y, _crtPoint.Y),
                                               Math.Abs(_prePoint.X - _crtPoint.X),
                                               Math.Abs(_prePoint.Y - _crtPoint.Y));
                if (Control.ModifierKeys == Keys.Shift)
                {
                    rect.Width = rect.Height;
                }
                path.AddEllipse(rect);
                break;

            case enumPencilType.FreeCurve:
                if (_vertexts.Count < 3)
                {
                    return(null);
                }
                path.AddCurve(_vertexts.ToArray());
                break;

            case enumPencilType.ControlFreeCurve:
                if (_vertexts.Count < 3)
                {
                    return(null);
                }
                path.AddCurve(_vertexts.ToArray());
                break;

            case enumPencilType.Polygon:
                for (int i = 0; i < _vertexts.Count - 1; i++)
                {
                    path.AddLine(_vertexts[i], _vertexts[i + 1]);
                }
                path.AddLine(_vertexts[_vertexts.Count - 1], _crtPoint);
                if (_vertexts.Count > 2)
                {
                    path.AddLine(_crtPoint, _vertexts[0]);
                }
                break;

            case enumPencilType.Rectangle:
                Rectangle ellrect = new Rectangle(Math.Min(_prePoint.X, _crtPoint.X),
                                                  Math.Min(_prePoint.Y, _crtPoint.Y), Math.Abs(_prePoint.X - _crtPoint.X),
                                                  Math.Abs(_prePoint.Y - _crtPoint.Y));
                path.AddRectangle(ellrect);
                break;
            }
            return(path);
        }
示例#9
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Point[] myArray =
            {
                new Point(0,   166),
                new Point(9,   103),
                new Point(45,   45),
                new Point(103,   9),
                new Point(166, 0)
            };

            Point[] myArray2 =
            {
                new Point(166,   0),
                new Point(229,   9),
                new Point(287,  45),
                new Point(323, 103),
                new Point(332, 166)
            };

            Point[] myArray3 =
            {
                new Point(332, 166),
                new Point(323, 229),
                new Point(287, 287),
                new Point(229, 323),
                new Point(166, 332)
            };

            Point[] myArray4 =
            {
                new Point(166, 332),
                new Point(103, 323),
                new Point(45,  287),
                new Point(9,   229),
                new Point(0, 166)
            };

            GraphicsPath path = new GraphicsPath();

            path.AddCurve(myArray);
            path.AddCurve(myArray2);
            path.AddCurve(myArray3);
            path.AddCurve(myArray4);
            Region reg = new Region(path);

            this.Region = reg;
        }
示例#10
0
        //横折钩
        private void DrawHengzhegou(Graphics g)
        {
            PointF[] pointDraw = new PointF[3]; //横的一段
            pointDraw[0] = new PointF(points[1].X - widththick, points[1].Y);
            pointDraw[1] = new PointF(points[0].X + widththin * 2, points[0].Y);
            pointDraw[2] = new PointF(points[0].X, points[0].Y + widththin / 4);

            PointF[] pointline = new PointF[2]; //横的一段
            pointline[0] = new PointF(points[0].X - widththin, points[0].Y - widththin);
            pointline[1] = new PointF(pointDraw[0].X - widththin / 2, pointDraw[0].Y - widththin);

            PointF[] pointcurve1 = new PointF[4];   //弯头
            pointcurve1[0] = pointline[1];
            pointcurve1[1] = new PointF(pointcurve1[0].X + widththick / 2, pointcurve1[0].Y - widththick / 2);
            pointcurve1[2] = new PointF(points[1].X + widththin, points[1].Y);
            pointcurve1[3] = new PointF(points[1].X, points[1].Y + widththin * (float)Math.Cos(Math.PI / 6));

            PointF[] pointcurve2 = new PointF[7];   //右下曲线
            pointcurve2[0] = pointcurve1[3];
            pointcurve2[1] = points[2];
            pointcurve2[2] = points[3];
            pointcurve2[3] = points[4];
            pointcurve2[4] = points[5];
            pointcurve2[5] = new PointF(points[6].X, points[5].Y - widththick * 0.72f);
            pointcurve2[6] = new PointF(points[7].X, points[5].Y - widththick * 1.2f);

            PointF[] pointcurve3 = new PointF[7];   //左上曲线
            pointcurve3[0] = new PointF(pointcurve2[6].X, pointcurve2[6].Y - widththin / 2);
            pointcurve3[1] = new PointF(points[6].X, pointcurve2[5].Y - widththick / 2);
            pointcurve3[2] = new PointF(points[5].X, points[5].Y - widththick * 1.2f);  //勾底
            pointcurve3[3] = new PointF(points[4].X, points[4].Y - widththick * 1.2f);
            pointcurve3[4] = new PointF(points[3].X - widththick * 0.8f, points[3].Y - widththick * 0.9f);
            pointcurve3[5] = new PointF(points[2].X - widththick, points[2].Y);
            pointcurve3[6] = pointDraw[0];

            SolidBrush   brush = new SolidBrush(Color.Black);
            GraphicsPath path  = new GraphicsPath();

            //按轮廓顺序加入
            path.AddCurve(pointDraw);
            path.AddLines(pointline);
            path.AddCurve(pointcurve1);
            path.AddCurve(pointcurve2);
            path.AddCurve(pointcurve3);
            g.FillPath(brush, path);
            path.Dispose();
            brush.Dispose();
        }
示例#11
0
        //横折弯钩
        private void DrawHengzhewangou(Graphics g)
        {
            PointF[] pointDraw = new PointF[3]; //横的一段
            pointDraw[0] = new PointF(points[1].X, points[1].Y);
            pointDraw[1] = new PointF(points[0].X + widththin * 2, points[0].Y);
            pointDraw[2] = new PointF(points[0].X, points[0].Y + widththin / 4);

            PointF[] pointline = new PointF[2]; //横的一段
            pointline[0] = new PointF(points[0].X - widththin, points[0].Y - widththin);
            pointline[1] = new PointF(pointDraw[0].X - widththin / 2, pointDraw[0].Y - widththin);

            PointF[] pointcurve = new PointF[4];   //弯头
            pointcurve[0] = pointline[1];
            pointcurve[1] = new PointF(pointcurve[0].X + widththick / 2, pointcurve[0].Y - widththick / 2);
            pointcurve[2] = new PointF(points[1].X + widththick + widththin, points[1].Y);
            pointcurve[3] = new PointF(points[1].X + widththick, points[1].Y + widththin * (float)Math.Cos(Math.PI / 6));

            PointF[] pointcurve1 = new PointF[4];
            pointcurve1[0] = pointcurve[3];
            //pointcurve1[1] = new PointF(points[2].X + widththick, points[2].Y); //弧头
            pointcurve1[1] = new PointF(points[3].X + widththick * 0.9f, points[3].Y - widththick * 0.9f);  //弧中
            //pointcurve1[3] = new PointF(points[4].X, points[4].Y - widththick); //弧尾
            pointcurve1[2] = new PointF(points[5].X - widththick, points[5].Y - widththick);
            pointcurve1[3] = new PointF(points[7].X - widththin / 3, points[5].Y - widththick - (points[5].Y - points[0].Y) / 3);

            PointF[] pointcurve2 = new PointF[8];
            pointcurve2[0] = new PointF(pointcurve1[3].X + widththin / 3, pointcurve1[3].Y);
            pointcurve2[1] = new PointF(points[7].X, points[6].Y - (points[6].X - points[7].X));
            pointcurve2[2] = points[6];
            pointcurve2[3] = points[5];
            pointcurve2[4] = points[4];
            pointcurve2[5] = points[3];
            pointcurve2[6] = points[2];
            pointcurve2[7] = pointDraw[0];

            SolidBrush   brush = new SolidBrush(Color.Black);
            GraphicsPath path  = new GraphicsPath();

            //按轮廓顺序加入
            path.AddCurve(pointDraw);
            path.AddLines(pointline);
            path.AddCurve(pointcurve);
            path.AddCurve(pointcurve1, 0.2f);
            path.AddCurve(pointcurve2, 0.3f);
            g.FillPath(brush, path);
            path.Dispose();
            brush.Dispose();
        }
示例#12
0
        protected override Pen CreatePen(Color borderColor, int borderSize, BorderStyle borderStyle)
        {
            using (GraphicsPath gp = new GraphicsPath())
            {
                int arrowWidth = 2, arrowHeight = 6, arrowCurve = 1;
                gp.AddLine(new Point(0, 0), new Point(-arrowWidth, -arrowHeight));
                gp.AddCurve(new Point[] { new Point(-arrowWidth, -arrowHeight), new Point(0, -arrowHeight + arrowCurve), new Point(arrowWidth, -arrowHeight) });
                gp.CloseFigure();

                CustomLineCap lineCap = new CustomLineCap(gp, null)
                {
                    BaseInset = arrowHeight - arrowCurve
                };

                Pen pen = new Pen(borderColor, borderSize);

                if (ArrowHeadDirection == ArrowHeadDirection.Both && MathHelpers.Distance(Points[0], Points[Points.Length - 1]) > arrowHeight * borderSize * 2)
                {
                    pen.CustomEndCap = pen.CustomStartCap = lineCap;
                }
                else if (ArrowHeadDirection == ArrowHeadDirection.Start)
                {
                    pen.CustomStartCap = lineCap;
                }
                else
                {
                    pen.CustomEndCap = lineCap;
                }

                pen.LineJoin  = LineJoin.Round;
                pen.DashStyle = (DashStyle)borderStyle;
                return(pen);
            }
        }
示例#13
0
        //提
        private void DrawTi(Graphics g)
        {
            double k    = Math.Atan((points[1].X - points[0].X) / (points[0].Y - points[1].Y)); //计算点的总体斜角
            float  sink = (float)Math.Sin(k);
            float  cosk = (float)Math.Cos(k);

            //上方平横
            PointF[] pointline = new PointF[2];
            pointline[0] = new PointF(points[1].X, points[1].Y - widththin / 3);
            pointline[1] = new PointF(points[0].X - widththick / 2, points[0].Y - widththick);

            PointF[] pointCurve = new PointF[3];
            pointCurve[0] = pointline[1];
            pointCurve[1] = points[0];
            pointCurve[2] = points[1];

            SolidBrush   brush = new SolidBrush(Color.Black);
            GraphicsPath path  = new GraphicsPath();

            //按轮廓顺序加入
            path.AddLines(pointline);
            path.AddCurve(pointCurve, 0.1f);
            g.FillPath(brush, path);
            path.Dispose();
            brush.Dispose();
        }
示例#14
0
        private void RenderDataSet(Graphics graphics, Brush brush, Size size, List <int> dataSet)
        {
            if (dataSet.Count < 2)
            {
                return;
            }

            var deltaX  = (double)size.Width / (dataSet.Count - 1);
            var factorY = (double)size.Height / Max;

            var points = new Point[dataSet.Count];
            var index  = 0;
            var x      = 0.0;

            foreach (var v in dataSet)
            {
                var y = (int)(size.Height - v * factorY);
                points[index] = new Point((int)x, y);
                x            += deltaX;
                index++;
            }

            var p = new GraphicsPath();

            p.AddLine(size.Width, size.Height, 0, size.Height);
            p.AddCurve(points);

            graphics.FillPath(brush, p);
        }
示例#15
0
        public static GraphicsPath BuildPathPoints(Track track)
        {
            var path = new GraphicsPath();

            if (track.ControlPoints.Count < 2)
            {
                return(path);
            }

            var points = track.ControlPoints.Select(cp => cp.Point.ToPointF()).ToArray();

            path.AddCurve(points, Tension);
            path.Flatten(new Matrix(), Flatness);
            points = path.PathPoints;

            track.Points.Clear();
            for (var i = 0; i < points.Length; i++)
            {
                var p = points[i];
                track.Points.Add(new PathPoint {
                    Point = p, Width = 1
                });
            }

            return(path);
        }
示例#16
0
            /// <summary>
            /// Generates a random snowy terrain.
            /// </summary>
            private GraphicsPath CreateTerrain()
            {
                Random       rnd    = new Random();
                GraphicsPath path   = new GraphicsPath();
                int          width  = 100;
                int          height = 10;

                int count = 20;
                int step = width / count;
                int lastx = 0, lasty = 0;

                Point[] points = new Point[count];
                for (int i = 0; i < count; i++)
                {
                    int x = i * (width + 2 * step) / count - step;
                    int y = rnd.Next(-height / 2, height / 2);
                    points[i] = new Point(x, y);
                    lastx     = x;
                    lasty     = y;
                }
                path.AddCurve(points);

                path.AddLine(lastx, lasty, width + step, 0);
                path.AddLine(width + step, 0, width + step, 200);
                path.AddLine(width + step, 200, -step, 200);
                path.CloseFigure();

                return(path);
            }
示例#17
0
        protected override Pen CreatePen(Color borderColor, int borderSize)
        {
            using (GraphicsPath gp = new GraphicsPath())
            {
                int arrowWidth = 2, arrowHeight = 6, arrowCurve = 1;
                gp.AddLine(new Point(0, 0), new Point(-arrowWidth, -arrowHeight));
                gp.AddCurve(new Point[] { new Point(-arrowWidth, -arrowHeight), new Point(0, -arrowHeight + arrowCurve), new Point(arrowWidth, -arrowHeight) });
                gp.CloseFigure();

                CustomLineCap lineCap = new CustomLineCap(gp, null)
                {
                    BaseInset = arrowHeight - arrowCurve
                };

                Pen pen = new Pen(borderColor, borderSize);
                pen.CustomEndCap = lineCap;

                if (ArrowHeadsBothSide)
                {
                    pen.CustomStartCap = lineCap;
                }

                pen.LineJoin = LineJoin.Round;
                return(pen);
            }
        }
示例#18
0
    public void Method23(PaintEventArgs e)
    {
        Graphics myGraphics = e.Graphics;
        // <snippet23>
        SolidBrush   mySolidBrush   = new SolidBrush(Color.Aqua);
        GraphicsPath myGraphicsPath = new GraphicsPath();

        Point[] myPointArray =
        {
            new Point(15, 20),
            new Point(20, 40),
            new Point(50, 30)
        };

        FontFamily   myFontFamily   = new FontFamily("Times New Roman");
        PointF       myPointF       = new PointF(50, 20);
        StringFormat myStringFormat = new StringFormat();

        myGraphicsPath.AddArc(0, 0, 30, 20, -90, 180);
        myGraphicsPath.AddCurve(myPointArray);
        myGraphicsPath.AddString("a string in a path", myFontFamily,
                                 0, 24, myPointF, myStringFormat);
        myGraphicsPath.AddPie(230, 10, 40, 40, 40, 110);

        myGraphics.FillPath(mySolidBrush, myGraphicsPath);
        myGraphics.DrawPath(myPen, myGraphicsPath);
        // </snippet23>
    }
示例#19
0
        // </snippet16>

        // Snippet for: M:System.Drawing.Drawing2D.GraphicsPath.CloseAllFigures
        // <snippet17>
        private void CloseAllFiguresExample(PaintEventArgs e)
        {
            // Create a path containing several open-ended figures.
            GraphicsPath myPath = new GraphicsPath();

            myPath.StartFigure();
            myPath.AddLine(new Point(10, 10), new Point(150, 10));
            myPath.AddLine(new Point(150, 10), new Point(10, 150));
            myPath.StartFigure();
            myPath.AddArc(200, 200, 100, 100, 0, 90);
            myPath.StartFigure();
            Point point1 = new Point(300, 300);
            Point point2 = new Point(400, 325);
            Point point3 = new Point(400, 375);
            Point point4 = new Point(300, 400);

            Point[] points = { point1, point2, point3, point4 };
            myPath.AddCurve(points);

            // Close all the figures.
            myPath.CloseAllFigures();

            // Draw the path to the screen.
            e.Graphics.DrawPath(new Pen(Color.Black, 3), myPath);
        }
        /// <summary>
        /// Gets the path.
        /// </summary>
        /// <param name="shape">The shape.</param>
        /// <param name="points">The points.</param>
        /// <returns>GraphicsPath.</returns>
        /// <exception cref="ArgumentException">For Beziers, the points array must include the starting point, and three extra points for each segment</exception>
        private GraphicsPath GetPath(Shapes shape, PointF[] points)
        {
            GraphicsPath path = new GraphicsPath();

            switch (shape)
            {
            case Shapes.Line:
                path.AddLines(points);
                break;

            case Shapes.Curve:
                path.AddCurve(points, 1, points.Length - 3, _Tension / 100f);
                break;

            case Shapes.Bezier:

                if (points.Length < 4 || points.Length % 3 != 1)
                {
                    throw new ArgumentException("For Beziers, the points array must include the starting point, and three extra points for each segment");
                }

                path.AddBeziers(points);

                break;

            default:
                Debug.Assert(false);
                break;
            }

            return(path);
        }
示例#21
0
        private void AddMoodLayer(Graphics g, MoodDataSet mood, bool showDataPoints)
        {
            PointF bottomRight = new PointF(this.Width, this.Height);
            PointF bottomLeft  = new PointF(0, this.Height);
            var    color       = mood.Mood.DisplayColor;
            Pen    pen         = new Pen(color, 2);
            var    dataPoints  = mood.DataPoints.Select(dp => DataPointToPoint(dp)).ToList();
            var    last        = dataPoints[dataPoints.Count - 1];

            GraphicsPath path = new GraphicsPath();

            path.AddCurve(dataPoints.ToArray(), this.Tension);
            last.X = bottomRight.X;
            path.AddLine(last, bottomRight);
            path.AddLine(bottomRight, bottomLeft);
            path.AddLine(bottomLeft, dataPoints.First());
            g.FillPath(new SolidBrush(color), path);

            if (ShowDataPoints)
            {
                var dpW = _dataPointWidth / 2;
                foreach (var dp in dataPoints)
                {
                    g.FillEllipse(new SolidBrush(Color.Black), dp.X - dpW, dp.Y - dpW, _dataPointWidth, _dataPointWidth);
                }
            }
        }
        public MainForm()
        {
            // Load some local images.
            myImages[0] = new Bitmap("imageA.bmp");
            myImages[1] = new Bitmap("imageB.bmp");
            myImages[2] = new Bitmap("imageC.bmp");

            // Set up the rectangles.
            imageRects[0] = new Rectangle(10, 10, 90, 90);
            imageRects[1] = new Rectangle(10, 110, 90, 90);
            imageRects[2] = new Rectangle(10, 210, 90, 90);

            // Create an interesting path.
            myPath.StartFigure();
            myPath.AddLine(new Point(150, 10), new Point(120, 150));
            myPath.AddArc(200, 200, 100, 100, 0, 90);
            Point point1 = new Point(250, 250);
            Point point2 = new Point(350, 275);
            Point point3 = new Point(350, 325);
            Point point4 = new Point(250, 350);

            Point[] points = { point1, point2, point3, point4 };
            myPath.AddCurve(points);
            myPath.CloseFigure();

            CenterToScreen();
            InitializeComponent();
        }
示例#23
0
        public GraphicsPath Get()
        {
            var path = new GraphicsPath();

            path.AddCurve(this.nodes.GetPoints());
            return(path);
        }
示例#24
0
        private GraphicsPath ToGraphicsPath(CodeCell.AgileMap.Core.Feature feature, ICanvas canvas)
        {
            CodeCell.AgileMap.Core.ShapePolyline           ply = feature.Geometry as CodeCell.AgileMap.Core.ShapePolyline;
            GeoDo.RSS.Core.DrawEngine.ICoordinateTransform tran = canvas.CoordTransform;
            double       prjX, prjY;
            int          screenX, screenY;
            GraphicsPath path = new GraphicsPath();

            foreach (CodeCell.AgileMap.Core.ShapeLineString line in ply.Parts)
            {
                PointF[] pts = new PointF[line.Points.Length];
                for (int i = 0; i < pts.Length; i++)
                {
                    if (!feature.Projected)
                    {
                        tran.Geo2Prj(line.Points[i].X, line.Points[i].Y, out prjX, out prjY);
                    }
                    else
                    {
                        prjX = line.Points[i].X;
                        prjY = line.Points[i].Y;
                    }
                    tran.Prj2Screen(prjX, prjY, out screenX, out screenY);
                    pts[i].X = screenX;
                    pts[i].Y = screenY;
                }
                path.AddCurve(pts.ToArray());
                //path.AddLines();
                path.StartFigure();
            }
            return(path);
        }
示例#25
0
 /// <summary>
 /// See <see cref="GraphicsPath.AddCurve">GraphicsPath.AddCurve</see>.
 /// </summary>
 public virtual void AddCurve(PointF[] points)
 {
     path.AddCurve(points);
     UpdateBoundsFromPath();
     InvalidatePaint();
     InvalidateVertices();
 }
示例#26
0
    public void Method103(PaintEventArgs e)
    {
        Graphics myGraphics = e.Graphics;
        // <snippet103>
        GraphicsPath myGraphicsPath = new GraphicsPath();

        Point[] myPointArray =
        {
            new Point(5,  30),
            new Point(20, 40),
            new Point(50, 30)
        };

        FontFamily   myFontFamily   = new FontFamily("Times New Roman");
        PointF       myPointF       = new PointF(50, 20);
        StringFormat myStringFormat = new StringFormat();

        myGraphicsPath.AddArc(0, 0, 30, 20, -90, 180);
        myGraphicsPath.StartFigure();
        myGraphicsPath.AddCurve(myPointArray);
        myGraphicsPath.AddString("a string in a path", myFontFamily,
                                 0, 24, myPointF, myStringFormat);
        myGraphicsPath.AddPie(230, 10, 40, 40, 40, 110);
        myGraphics.DrawPath(myPen, myGraphicsPath);
        // </snippet103>
    }
示例#27
0
        private void chart1_Paint(object sender, PaintEventArgs e)          ///// ДОДЕЛАТЬ
        {
            Graphics     fill     = e.Graphics;
            GraphicsPath fillPath = new GraphicsPath(FillMode.Alternate);

            Axis ax = chart1.ChartAreas[0].AxisX;
            Axis ay = chart1.ChartAreas[0].AxisY;

            PointF[] points = chart1.Series["Bounds"].Points.Select(x => new PointF
            {
                X = (float)ax.ValueToPixelPosition(x.XValue),
                Y = (float)ay.ValueToPixelPosition(x.YValues[0])
            }).ToArray();

            fillPath.AddLines(points);

            points = chart1.Series["Function"].Points.Select(x => new PointF
            {
                X = (float)ax.ValueToPixelPosition(x.XValue),
                Y = (float)ay.ValueToPixelPosition(x.YValues[0])
            }).ToArray();

            fillPath.AddCurve(points); // Все происходит здесь.

            SolidBrush brush = new SolidBrush(Color.DarkBlue);

            fill.FillPath(brush, fillPath);

            fillPath.Dispose();
        }
示例#28
0
        private bool IsPointInObject(Point _point)
        {
            // _point is descaled.

            // Create path which contains wide line for easy mouse selection
            GraphicsPath areaPath = new GraphicsPath();

            Point[] points = new Point[m_PointList.Count];
            for (int i = 0; i < points.Length; i++)
            {
                points[i] = new Point(m_PointList[i].X, m_PointList[i].Y);
            }
            areaPath.AddCurve(points, 0.5f);

            Pen areaPen = new Pen(Color.Black, m_PenStyle.Size + 7);

            areaPen.StartCap = LineCap.Round;
            areaPen.EndCap   = LineCap.Round;
            areaPen.LineJoin = LineJoin.Round;

            areaPath.Widen(areaPen);

            // Create region from the path
            Region areaRegion = new Region(areaPath);

            return(areaRegion.IsVisible(_point));
        }
示例#29
0
        private GraphicsPath CreateFishPath()
        {
            // The bounding box for the fish is slightly smaller than the client area
            Rectangle fishRect = ClientRectangle;

            fishRect.Inflate(-5, -5);

            // Find some lengths
            int w3 = Width / 3;
            int w6 = Width / 6;
            int h2 = Height / 2;
            int h4 = Height / 4;

            GraphicsPath fishPath = new GraphicsPath();

            // Create the tail of the fish
            fishPath.AddLine(fishRect.Left + w6, fishRect.Bottom - h4, fishRect.Left, fishRect.Bottom);
            fishPath.AddLine(fishRect.Left, fishRect.Bottom, fishRect.Left, fishRect.Top);
            fishPath.AddLine(fishRect.Left, fishRect.Top, fishRect.Left + w6, fishRect.Top + h4);

            // Create the curving body of the fish
            fishPath.AddCurve(new Point[] { new Point(fishRect.Left + w6, fishRect.Top + h4),
                                            new Point(fishRect.Right - w3, fishRect.Top),
                                            new Point(fishRect.Right, fishRect.Top + h2),
                                            new Point(fishRect.Right - w3, fishRect.Bottom),
                                            new Point(fishRect.Left + w6, fishRect.Bottom - h4) }, 0.8f);

            return(fishPath);
        }
示例#30
0
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            // Fill the images with bitmaps.
            bMapImageA = new Bitmap("imageA.bmp");
            bMapImageB = new Bitmap("imageB.bmp");
            bMapImageC = new Bitmap("imageC.bmp");

            // Create an interesting region.
            myPath.StartFigure();
            myPath.AddLine(new Point(150, 10), new Point(120, 150));
            myPath.AddArc(200, 200, 100, 100, 0, 90);
            Point point1 = new Point(250, 250);
            Point point2 = new Point(350, 275);
            Point point3 = new Point(350, 325);
            Point point4 = new Point(250, 350);

            Point[] points = { point1, point2, point3, point4 };
            myPath.AddCurve(points);
            myPath.CloseFigure();

            CenterToScreen();
        }
示例#31
0
    private void IrregularForm_Load(object sender, EventArgs e)
    {
        GraphicsPath path = new GraphicsPath();

        Point[] pointsA = new Point[] { new Point(0, 0), new Point(40, 60), new Point(this.Width - 100, 10) };
        path.AddCurve(pointsA);

        Point[] pointsB = new Point[]{
                new Point(this.Width - 40, this.Height - 60),
                new Point(this.Width, this.Height),
                new Point(10, this.Height)
            };
        path.AddCurve(pointsB);

        path.CloseAllFigures();

        this.Region = new Region(path);
    }