Files
docs-desktop/dotnet-desktop-guide/framework/winforms/advanced/how-to-draw-a-line-filled-with-a-texture.md
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

2.3 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Draw a Line Filled with a Texture 03/30/2017
csharp
vb
drawing [Windows Forms], lines
lines [Windows Forms], texture
drawing lines [Windows Forms], texture
dc9118cc-f3c2-42e5-8173-f46d41d18fd5

How to: Draw a Line Filled with a Texture

Instead of drawing a line with a solid color, you can draw a line with a texture. To draw lines and curves with a texture, create a xref:System.Drawing.TextureBrush object, and pass that xref:System.Drawing.TextureBrush object to a xref:System.Drawing.Pen.%23ctor%2A constructor. The bitmap associated with the texture brush is used to tile the plane (invisibly), and when the pen draws a line or curve, the stroke of the pen uncovers certain pixels of the tiled texture.

Example

The following example creates a xref:System.Drawing.Bitmap object from the file Texture1.jpg. That bitmap is used to construct a xref:System.Drawing.TextureBrush object, and the xref:System.Drawing.TextureBrush object is used to construct a xref:System.Drawing.Pen object. The call to xref:System.Drawing.Graphics.DrawImage%2A draws the bitmap with its upper-left corner at (0, 0). The call to xref:System.Drawing.Graphics.DrawEllipse%2A uses the xref:System.Drawing.Pen object to draw a textured ellipse.

The following illustration shows the bitmap and the textured ellipse:

Screenshot that shows the bitmap and the textured ellipse.

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

Compiling the Code

Create a Windows Form and handle the form's xref:System.Windows.Forms.Control.Paint event. Paste the preceding code into the xref:System.Windows.Forms.Control.Paint event handler. Replace Texture.jpg with an image valid on your system.

See also