public override void Draw(Graphics g)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;

            Pen pen;

            if (DrawPen == null)
            {
                pen = new Pen(Color, PenWidth);
                DrawingPens.SetCurrentPen(ref pen, PenType, EndCap);
            }
            else
            {
                pen = (Pen)DrawPen.Clone();
            }
            GraphicsPath gp = new GraphicsPath();

            gp.AddLine(startPoint, endPoint);
            // Rotate the path about it's center if necessary
            if (Rotation != 0)
            {
                RectangleF pathBounds = gp.GetBounds();
                Matrix     m          = new Matrix();
                m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append);
                gp.Transform(m);
            }
            g.DrawPath(pen, gp);
            gp.Dispose();
            pen.Dispose();
        }
예제 #2
0
        public override void Draw(Graphics g)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Pen pen;

            if (DrawPen == null)
            {
                pen = new Pen(Color, PenWidth);
                DrawingPens.SetCurrentPen(ref pen, PenType, EndCap);
            }
            else
            {
                pen = DrawPen.Clone() as Pen;
            }

            Point[] pts = new Point[pointArray.Count];
            for (int i = 0; i < pointArray.Count; i++)
            {
                Point px = (Point)pointArray[i];
                pts[i] = px;
            }
            byte[] types = new byte[pointArray.Count];
            for (int i = 0; i < pointArray.Count; i++)
            {
                types[i] = (byte)PathPointType.Line;
            }
            GraphicsPath gp = new GraphicsPath(pts, types);

            // Rotate the path about it's center if necessary
            if (Rotation != 0)
            {
                RectangleF pathBounds = gp.GetBounds();
                Matrix     m          = new Matrix();
                m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append);
                gp.Transform(m);
            }
            g.DrawPath(pen, gp);
            //g.DrawCurve(pen, pts);
            gp.Dispose();
            if (pen != null)
            {
                pen.Dispose();
            }
        }
예제 #3
0
        /// <summary>
        /// Draw rectangle
        /// </summary>
        /// <param name="g"></param>
        public override void Draw(Graphics g)
        {
            Pen   pen;
            Brush b = new SolidBrush(FillColor);

            if (DrawPen == null)
            {
                pen = new Pen(Color, PenWidth);
                DrawingPens.SetCurrentPen(ref pen, PenType, EndCap);
            }
            else
            {
                pen = (Pen)DrawPen.Clone();
            }

            GraphicsPath gp = new GraphicsPath();

            gp.AddRectangle(GetNormalizedRectangle(Rectangle));
            // Rotate the path about it's center if necessary
            if (Rotation != 0)
            {
                RectangleF pathBounds = gp.GetBounds();
                Matrix     m          = new Matrix();
                m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append);
                gp.Transform(m);
            }

            if (Filled)
            {
                g.FillPath(b, gp);
            }
            g.DrawPath(pen, gp);

            gp.Dispose();
            pen.Dispose();
            b.Dispose();
        }
        public override void Draw(Graphics g)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Pen pen;

            if (DrawPen == null)
            {
                pen = new Pen(Color, PenWidth);
                DrawingPens.SetCurrentPen(ref pen, PenType, EndCap);
            }
            else
            {
                pen = DrawPen.Clone() as Pen;
            }

            // Convert the array of points to a GraphicsPath object so lines are mitered correctly at the intersections
            // (not to mention the object is drawn faster then drawing individual lines)
            Point[] pts = new Point[pointArray.Count];
            for (int i = 0; i < pointArray.Count; i++)
            {
                Point px = (Point)pointArray[i];
                pts[i] = px;
            }
            byte[] types = new byte[pointArray.Count];
            for (int i = 0; i < pointArray.Count; i++)
            {
                types[i] = (byte)PathPointType.Line;
            }
            GraphicsPath gp = new GraphicsPath(pts, types);

            // Rotate the path about it's center if necessary
            if (Rotation != 0)
            {
                RectangleF pathBounds = gp.GetBounds();
                Matrix     m          = new Matrix();
                m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append);
                gp.Transform(m);
            }
            g.DrawPath(pen, gp);
            //g.DrawCurve(pen, pts);
            //
            //// For DrawBeziers() to work, the pts array must have a minimum of 4 points.
            //// The pts array may have more than 4 points, but if so, then after the first 4 points, remaining points must be in sets of 3 for the call to work.
            //// The following code will adjust the pts array to properly fit these requirements.
            //int numPoints = pts.Length;
            //if (numPoints - 4 <= 0)
            //{
            //    // Cannot call DrawBeziers() so return, drawing nothing.
            //    gp.Dispose();
            //    pen.Dispose();
            //    return;
            //}
            //while ((numPoints - 4) % 3 != 0 && numPoints - 4 > 0)
            //{
            //    // Chop off the last point from the pts array
            //    numPoints--;
            //    Array.Resize(ref pts, numPoints);
            //}
            //g.DrawBeziers(pen, pts);
            gp.Dispose();
            if (pen != null)
            {
                pen.Dispose();
            }
        }