Exemplo n.º 1
0
        public override void Draw(Graphics g, Point startPoint, Point endPoint)
        {
            GPath = new System.Drawing.Drawing2D.GraphicsPath();
            GPath.AddLine(startPoint, endPoint);

            // OutOfMemoryException if two points equal
            if (startPoint != endPoint)
            {
                try
                {
                    GPath.Widen(new Pen(Color.Red, 50F));
                }
                catch
                {
                    // Do nothing
                }
            }

            g.DrawLine(ArrowPen, startPoint, endPoint);

            if (IsFocused || !string.IsNullOrEmpty(MiddleText))
            {
                int    textHeight = (int)Math.Ceiling(g.MeasureString("A", Font).Height);
                double angle      = ShapeHelper.GetAngleBetween2PointsInDegrees(startPoint, endPoint);

                if (IsFocused && !String.IsNullOrEmpty(StartText))
                {
                    int   textLength = (int)Math.Ceiling(g.MeasureString(StartText, Font).Width);
                    Point textPoint  = ShapeHelper.GetPointOnCircle(startPoint, 40, angle);
                    textPoint.X  = textPoint.X - textLength / 2;
                    textPoint.Y -= textHeight / 2;
                    g.FillRectangle(new SolidBrush(Color.White), new Rectangle(textPoint.X, textPoint.Y, textLength, textHeight));
                    g.DrawString(StartText, Font, TextBrush, textPoint);
                }
                if (IsFocused && !string.IsNullOrEmpty(EndText))
                {
                    int   textLength = (int)Math.Ceiling(g.MeasureString(EndText, Font).Width);
                    Point textPoint  = ShapeHelper.GetPointOnCircle(endPoint, -40, angle);
                    textPoint.X  = textPoint.X - textLength / 2;
                    textPoint.Y -= textHeight / 2;
                    g.FillRectangle(new SolidBrush(Color.White), new Rectangle(textPoint.X, textPoint.Y, textLength, textHeight));
                    g.DrawString(EndText, Font, TextBrush, textPoint);
                }
                if (!string.IsNullOrEmpty(MiddleText))
                {
                    int    textLength = (int)Math.Ceiling(g.MeasureString(MiddleText, Font).Width);
                    double lineLength = ShapeHelper.GetLineLength(startPoint, endPoint);
                    Point  textPoint  = ShapeHelper.GetPointOnCircle(startPoint, (int)(lineLength / 2), angle);
                    textPoint.X  = textPoint.X - textLength / 2;
                    textPoint.Y -= textHeight / 2;
                    g.FillRectangle(new SolidBrush(Color.White), new Rectangle(textPoint.X, textPoint.Y, textLength, textHeight));
                    g.DrawString(MiddleText, Font, TextBrush, textPoint);
                }
            }
        }
Exemplo n.º 2
0
        public override bool HitTest(System.Drawing.Point p)
        {
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();

            Pen pn = new Pen(Color.Black, 10);

            gp.AddLines(myPts);
            gp.Widen(pn);

            gp.IsVisible(p);

            pn.Dispose();

            return(gp.IsVisible(p));
        }