System.Drawing.Graphics.DrawLine C# (CSharp) Method

DrawLine() public method

public DrawLine ( Pen pen, Point pt1, Point pt2 ) : void
pen Pen
pt1 Point
pt2 Point
return void
        public void DrawLine(Pen pen, Point pt1, Point pt2)
        {
            if (pen == null)
                throw new ArgumentNullException ("pen");

            // DrawLine is throwing an assertion error on MonoTouch
            // Assertion failed: (CGFloatIsValid(x) && CGFloatIsValid(y))
            // , function void CGPathAddLineToPoint(CGMutablePathRef, const CGAffineTransform *, CGFloat, CGFloat)
            // What we will do here is not draw the line at all if any of the points are Single.NaN
            if (!float.IsNaN(pt1.X) && !float.IsNaN(pt1.Y) &&
                !float.IsNaN(pt2.X) && !float.IsNaN(pt2.Y))
            {
                MoveTo (pt1.X, pt1.Y);
                LineTo (pt2.X, pt2.Y);
                StrokePen (pen);
            }
        }

Same methods

Graphics::DrawLine ( Pen pen, PointF pt1, PointF pt2 ) : void
Graphics::DrawLine ( Pen pen, float x1, float y1, float x2, float y2 ) : void
Graphics::DrawLine ( Pen pen, int x1, int y1, int x2, int y2 ) : void

Usage Example

Example #1
1
        public void Draw(Graphics g)
        {
            Pen p = new Pen(Color.Green, 1f);

            g.DrawLine(p, 0, height / 2, width, height / 2);
            g.DrawLine(p, width / 2, 0, width / 2, height);
        }
All Usage Examples Of System.Drawing.Graphics::DrawLine