.NET Framework Class Library
Rectangle Class

Draws a rectangle.

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

Visual Basic (Declaration)
Public NotInheritable Class Rectangle _
    Inherits Shape
Visual Basic (Usage)
Dim instance As Rectangle
C#
public sealed class Rectangle : Shape
Visual C++
public ref class Rectangle sealed : public Shape
JScript
public final class Rectangle extends Shape
XAML Object Element Usage
<Rectangle .../>
Examples

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.

Visual Basic
'Add a Rectangle Element
Dim myRect As New Rectangle()
myRect.Stroke = Brushes.Black
myRect.Stroke = Brushes.Black
myRect.Fill = Brushes.SkyBlue
myRect.HorizontalAlignment = HorizontalAlignment.Left
myRect.VerticalAlignment = VerticalAlignment.Center
myRect.Height = 50
myRect.Width = 50
myGrid.Children.Add(myRect)
Visual C++
// Add a Rectangle Element
myRect = gcnew Rectangle();
myRect->Stroke = Brushes::Black;
myRect->Fill = Brushes::SkyBlue;
myRect->HorizontalAlignment = HorizontalAlignment::Left;
myRect->VerticalAlignment = VerticalAlignment::Center;
myRect->Height = 50;
myRect->Width = 50;
myGrid->Children->Add(myRect);
C#
// 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;
myGrid.Children.Add(myRect);

More Code

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

System..::.Object
  System.Windows.Threading..::.DispatcherObject
    System.Windows..::.DependencyObject
      System.Windows.Media..::.Visual
        System.Windows..::.UIElement
          System.Windows..::.FrameworkElement
            System.Windows.Shapes..::.Shape
              System.Windows.Shapes..::.Rectangle
Thread Safety

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

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.
Version Information

.NET Framework

Supported in: 3.5, 3.0
See Also

Reference

Other Resources

Tags :


Page view tracker