* Merge winforms framework content to working branch (#14) * Breadcrumb / TOC / Move net5 to net folder (#15) * change path from net5 to net * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Mess with bread/toc * Add .net 5 winforms placeholder article (#16) * added some metadata and adjusted net5 placeholder * corrections * corrections * corrections * Test1 * Swapping landing page vs concept * fix links * Fix links * Fix desc
1.8 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | ||||
|---|---|---|---|---|---|---|---|---|
| How to: Use a Pen to Draw Lines | 03/30/2017 |
|
|
0828c331-a438-4bdd-a4d6-3ef1e59e8795 |
How to: Use a Pen to Draw Lines
To draw lines, you need a xref:System.Drawing.Graphics object and a xref:System.Drawing.Pen object. The xref:System.Drawing.Graphics object provides the xref:System.Drawing.Graphics.DrawLine%2A method, and the xref:System.Drawing.Pen 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 xref:System.Drawing.Pen.%23ctor%2A class constructor to create a black pen. The one argument passed to the xref:System.Drawing.Pen.%23ctor%2A constructor is a xref:System.Drawing.Color object created with the xref:System.Drawing.Color.FromArgb%2A method. The values used to create the xref:System.Drawing.Color 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-csharpSystem.Drawing.UsingAPen#11] [!code-vbSystem.Drawing.UsingAPen#11]
Compiling the Code
The preceding example is designed for use with Windows Forms, and it requires xref:System.Windows.Forms.PaintEventArgs e, which is a parameter of the xref:System.Windows.Forms.Control.Paint event handler.