How to Draw a Line Between Two Points Ti84
This article has been excerpted from book "Graphics Programming with GDI+ ". The DrawLine method draws a line between two points specified by a pair of coordinates. DrawLines draws a series of lines using an array of points. DrawLine has four overloaded methods. The first argument of all DrawLine methods is a Pen object, with texture, color, and width attributes. The rest of the arguments vary. You can use two points with integer or floating point values, or you can pass four integer or floating point values directly: To draw a line, an application first creates a Pen object, that defines the color and width. The following line of code creates a red pen with a width of 1: Pen After that we define the endpoints of the line: Finally, we use the pen and points as input to DrawLine: Graphics Listing 3.1 shows how to use the various overloaded methods. We create four pens with different colors and widths. After that we call DrawLine with various values, including integer, floating point, and Point structures, to draw four different lines. Three of them start at point (20,20). LISTING 3.1: Drawing lines private // Draw line using float coordinates // Draw line using Point structure //Draw line using PointF structures // Draw line using integer coordinates //Dispose of objects Drawing Connected Lines FIGURE 3.1: Using DrawLine to draw lines public To draw lines using DrawLines, an application first creates a Pen object, then creates an array of points, and then calls DrawLines. The code in Listing 3.2 draws three line segments. LISTING 3.2: Using DrawLines to draw connected lines PointF[] ptsArray= e.Graphics.DrawLines (redPen, ptsArray); The code in Listing 3.2 draws what is shown in Figure 3.2. FIGURE 3.2: Using DrawLines to draw connected lines I hope this article has helped you understand drawing lines. Read other articles on GDI+ on the website.
public void DrawLine (Pen, Point, Point);
public void DrawLine (Pen, PointF, PointF);
public void DrawLine (Pen, int, int, int, int);
public void DrawLine (Pen, float, float, float, float);
float x1 = 20.0F, y1 = 25.0F;
float x2 = 200.0F, y2 = 100.0F;
{
// Create four Pen objects with red,
// blue, green, and black colors and
// different widths
Pen redPen = new Pen(Color.Red, 1);
Pen bluePen = new Pen(Color.Blue, 2);
Pen greenPen = new Pen(Color.Green, 3);
Pen blackPen = new Pen(Color.Black, 4);
float x1 = 20.0F, y1 = 20.0F;
float x2 = 200.0F, y2 = 20.0F;
e.Graphics.DrawLine(redPen, x1, y1, x2, y2);
Point p1 = new Point(20, 20);
Point p2 = new Point(20, 200);
e.Graphics.DrawLine(greenPen, p1, p2);
PointF ptf1 = new PointF(20.0F, 20.0f);
PointF ptf2 = new PointF(200.0F, 200.0f);
e.Graphics.DrawLine(bluePen, ptf1, ptf2);
int X1 = 60, Y1 = 40, X2 = 250, Y2 = 100;
e.Graphics.DrawLine(blackPen, X1, Y1, X2, Y2);
redPen.Dispose();
bluePen.Dispose();
greenPen.Dispose();
blackPen.Dispose();
}
Sometimes we need to draw multiple connected straight line segments. One way to do this is to call the DrawLine method multiples times.
The Graphics class also provides the DrawLine method, that can be used to draw multiple connected lines. This method has two overloaded forms. One takes an array of Point structure objects, and the other takes an array of PointF structure objects:
public void DrawLine (Pen, PointF []);
{
new PointF(20.0F, 20.0F),
new PointF (20.0F, 20.0F),
new PointF (200.0F, 200.0F),
new PointF (20.0F, 20.0F)
};
Conclusion
This book teaches .NET developers how to work with GDI+ as they develop applications that include graphics, or that interact with monitors or printers. It begins by explaining the difference between GDI and GDI+, and covering the basic concepts of graphics programming in Windows. |
How to Draw a Line Between Two Points Ti84
Source: https://www.c-sharpcorner.com/UploadFile/mahesh/drawing-lines-in-gdi/
0 Response to "How to Draw a Line Between Two Points Ti84"
Postar um comentário