Pen.Thickness Property

Gets or sets the thickness of the stroke produced by this Pen.

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

'Declaration
Public Property Thickness As Double
<object Thickness="double" .../>

Property Value

Type: System.Double
The thickness of the stroke produced by this Pen. Default is 1.

Identifier field

ThicknessProperty

Metadata properties set to true

None

Thickness is relative to the geometry of the shape associated with this pen. Negative values are treated as though they were positive.

This example shows how use a Pen to outline a shape. To create a simple Pen, you need only specify its Thickness and Brush. You can create more complex pen's by specifying a DashStyle, DashCap, LineJoin, StartLineCap, and EndLineCap.

The following example uses a Pen to outline a shape defined by a GeometryDrawing.


Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Media
Namespace SDKSample
	Partial Public Class PenExample
		Inherits Page
		Public Sub New()
			' Create several geometries.
			Dim myRectangleGeometry As New RectangleGeometry()
			myRectangleGeometry.Rect = New Rect(0, 0, 50, 50)
			Dim myEllipseGeometry As New EllipseGeometry()
			myEllipseGeometry.Center = New Point(75, 75)
			myEllipseGeometry.RadiusX = 50
			myEllipseGeometry.RadiusY = 50
			Dim myLineGeometry As New LineGeometry()
			myLineGeometry.StartPoint = New Point(75, 75)
			myLineGeometry.EndPoint = New Point(75, 0)

			' Create a GeometryGroup and add the geometries to it.
			Dim myGeometryGroup As New GeometryGroup()
			myGeometryGroup.Children.Add(myRectangleGeometry)
			myGeometryGroup.Children.Add(myEllipseGeometry)
			myGeometryGroup.Children.Add(myLineGeometry)

			' Create a GeometryDrawing and use the GeometryGroup to specify
			' its geometry.
			Dim myGeometryDrawing As New GeometryDrawing()
			myGeometryDrawing.Geometry = myGeometryGroup

			' Add the GeometryDrawing to a DrawingGroup.
			Dim myDrawingGroup As New DrawingGroup()
			myDrawingGroup.Children.Add(myGeometryDrawing)

			' Create a Pen to add to the GeometryDrawing created above.
			Dim myPen As New Pen()
			myPen.Thickness = 10
			myPen.LineJoin = PenLineJoin.Round
			myPen.EndLineCap = PenLineCap.Round

			' Create a gradient to use as a value for the Pen's Brush property.
			Dim firstStop As New GradientStop()
			firstStop.Offset = 0.0
			Dim c1 As New Color()
			c1.A = 255
			c1.R = 204
			c1.G = 204
			c1.B = 255
			firstStop.Color = c1
			Dim secondStop As New GradientStop()
			secondStop.Offset = 1.0
			secondStop.Color = Colors.Purple

			Dim myLinearGradientBrush As New LinearGradientBrush()
			myLinearGradientBrush.GradientStops.Add(firstStop)
			myLinearGradientBrush.GradientStops.Add(secondStop)

			myPen.Brush = myLinearGradientBrush
			myGeometryDrawing.Pen = myPen

			' Create an Image and set its DrawingImage to the Geometry created above.
			Dim myImage As New Image()
			myImage.Stretch = Stretch.None
			myImage.Margin = New Thickness(10)

			Dim myDrawingImage As New DrawingImage()
			myDrawingImage.Drawing = myDrawingGroup
			myImage.Source = myDrawingImage

			Me.Content = myImage

		End Sub
	End Class
End Namespace
<Page 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Background="White">

  <Image Stretch="None" Margin="20">
    <Image.Source>
      <DrawingImage>
        <DrawingImage.Drawing>
          <DrawingGroup>
            <GeometryDrawing>
              <GeometryDrawing.Geometry>
                <GeometryGroup>
                  <RectangleGeometry Rect="0,0,50,50" />
                  <EllipseGeometry Center="75,75" RadiusX="50" RadiusY="50" />
                  <LineGeometry StartPoint="75,75" EndPoint="75,0" />
                </GeometryGroup>
              </GeometryDrawing.Geometry>
              <GeometryDrawing.Pen>
                <Pen 
                  Thickness="10" 
                  LineJoin="Round" 
                  EndLineCap="Triangle"
                  StartLineCap="Round">
                  <Pen.Brush>
                    <LinearGradientBrush>
                      <GradientStop Offset="0.0" Color="#CCCCFF" />
                      <GradientStop Offset="1.0" Color="Purple" />
                    </LinearGradientBrush>
                  </Pen.Brush>
                </Pen>
              </GeometryDrawing.Pen>
            </GeometryDrawing>
          </DrawingGroup>
        </DrawingImage.Drawing>
      </DrawingImage>
    </Image.Source>
  </Image>






</Page>
A GeometryDrawing

Outlines produces by a Pen

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft