--- title: "How to: Use a Pen to Draw Lines" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "lines [Windows Forms], drawing" - "pens [Windows Forms], drawing lines" ms.assetid: 0828c331-a438-4bdd-a4d6-3ef1e59e8795 --- # How to: Use a Pen to Draw Lines To draw lines, you need a object and a object. The object provides the method, and the object stores features of the line, such as color and width. ## Example The following example draws a line from (20, 10) to (300, 100). The first statement uses the class constructor to create a black pen. The one argument passed to the constructor is a object created with the method. The values used to create the object — (255, 0, 0, 0) — correspond to the alpha, red, green, and blue components of the color. These values define an opaque black pen. [!code-csharp[System.Drawing.UsingAPen#11](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Drawing.UsingAPen/CS/Class1.cs#11)] [!code-vb[System.Drawing.UsingAPen#11](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Drawing.UsingAPen/VB/Class1.vb#11)] ## Compiling the Code The preceding example is designed for use with Windows Forms, and it requires `e`, which is a parameter of the event handler. ## See also - - [Using a Pen to Draw Lines and Shapes](using-a-pen-to-draw-lines-and-shapes.md) - [Pens, Lines, and Rectangles in GDI+](pens-lines-and-rectangles-in-gdi.md)