Files
docs-desktop/dotnet-desktop-guide/framework/winforms/advanced/how-to-set-pen-width-and-alignment.md
T
Andy De George c0ba284473 Initial winforms content migrated (#18)
* 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
2020-09-01 16:26:21 -07:00

3.9 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Set Pen Width and Alignment 03/30/2017
csharp
vb
pens [Windows Forms], setting width
pens [Windows Forms], setting alignment
a202af36-4d31-4401-a126-b232f51db581

How to: Set Pen Width and Alignment

When you create a xref:System.Drawing.Pen, you can supply the pen width as one of the arguments to the constructor. You can also change the pen width with the xref:System.Drawing.Pen.Width%2A property of the xref:System.Drawing.Pen class.

A theoretical line has a width of 0. When you draw a line that is 1 pixel wide, the pixels are centered on the theoretical line. If you draw a line that is more than one pixel wide, the pixels are either centered on the theoretical line or appear to one side of the theoretical line. You can set the pen alignment property of a xref:System.Drawing.Pen to determine how the pixels drawn with that pen will be positioned relative to theoretical lines.

The values xref:System.Drawing.Drawing2D.PenAlignment.Center, xref:System.Drawing.Drawing2D.PenAlignment.Outset, and xref:System.Drawing.Drawing2D.PenAlignment.Inset that appear in the following code examples are members of the xref:System.Drawing.Drawing2D.PenAlignment enumeration.

The following code example draws a line twice: once with a black pen of width 1 and once with a green pen of width 10.

To vary the width of a pen

To change the alignment of a pen

To create an inset pen

  • Change the green pen's alignment by modifying the third statement in the preceding code example as follows:

    [!code-csharpSystem.Drawing.UsingAPen#43] [!code-vbSystem.Drawing.UsingAPen#43]

    Now the pixels in the wide green line appear on the inside of the rectangle as shown in the following illustration:

    A rectangle drawn with black lines with the wide green line inside.

See also