Changes

Jump to: navigation, search

Drawing Graphics in C Sharp

754 bytes added, 21:23, 28 January 2008
Drawing Lines in C#
== Drawing Lines in C# ==
 
Lines are drawn in C# using the ''DrawLine()'' method of the Graphics Object. This method takes a pre-instantiated Pen object and two sets of x and y co-ordinates (the begin and end points of the line) as arguments. For example, to draw a line from 20, 20 to 200, 210 on our sample form:
 
<pre>
private void Form1_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Graphics graphicsObj;
 
graphicsObj = this.CreateGraphics();
 
Pen myPen = new Pen(System.Drawing.Color.Red, 5);
 
graphicsObj.DrawLine(myPen, 20, 20, 200, 210);
}
</pre>
 
The above code, when compiled and executed will result in the form appearing as follows:
 
[[Image:C_sharp_draw_line.jpg|Drawing a Line in C#]]

Navigation menu