This documentation is archived and is not being maintained.

Rectangle Class

Draws a rectangle.

Namespace:  System.Windows.Shapes
Assembly:  PresentationFramework (in PresentationFramework.dll)

public sealed class Rectangle : Shape
<Rectangle .../>

The following example shows how to create a Rectangle element and set its properties by using code. For the complete sample, see WPF Shapes Gallery Sample.

// Add a Rectangle Element
myRect = new System.Windows.Shapes.Rectangle();
myRect.Stroke = System.Windows.Media.Brushes.Black;
myRect.Fill = System.Windows.Media.Brushes.SkyBlue;
myRect.HorizontalAlignment = HorizontalAlignment.Left;
myRect.VerticalAlignment = VerticalAlignment.Center;
myRect.Height = 50;
myRect.Width = 50;

More Code

How to: Draw a Rectangle This example shows how to draw a rectangle by using the Rectangle element.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5, 3.0