public DrawLine ( |
||
pen | ||
pt1 | Point | |
pt2 | Point | |
return | void |
void DrawHorizontalLine(Graphics g, int y, Pen pen) { g.DrawLine(pen, new Point(0, y), new Point(g.VisibleClipBounds.Width, y)); }
void DrawAngledLines(Graphics graphics, Pen pen) { for (int x = 0; x <= 100; x += 10) { graphics.DrawLine(pen, new Point(x, 0), new Point(x + 50, 100)); } }This code creates a method that draws a series of diagonal lines across an image or control. The method uses a for loop to iterate through different x-coordinates, drawing a line from each starting point to an endpoint that is 50 pixels away and 100 pixels down. The Pen object passed into the method is used to draw the lines. These examples use the System.Drawing namespace, which is part of the .NET Framework Class Library.