Jun 17, 2025
This lecture explains the Graphics.DrawLine method from the System.Drawing namespace in .NET, covering its purpose, overloads, parameters, usage, and exceptions.
Graphics.DrawLine method draws a line connecting two specified points.DrawLine:
DrawLine(Pen, int x1, int y1, int x2, int y2) draws a line between two integer coordinate pairs.DrawLine(Pen, float x1, float y1, float x2, float y2) draws a line between two floating-point coordinate pairs.DrawLine(Pen, Point pt1, Point pt2) draws a line between two Point structures (integer values).DrawLine(Pen, PointF pt1, PointF pt2) draws a line between two PointF structures (floating-point values).Pen object, which sets the line's color, width, and style.ArgumentNullException is thrown if the pen parameter is null.Paint event handler, using PaintEventArgs e.Point) or floats (PointF).null.Using a Pen to Draw Lines and Shapes documentation for more drawing techniques.DrawLine in a sample Windows Forms project.