Desktop Functions:

   Smart Device Functions:

Show Recent Changes
Subscribe (RSS)
Misc. Pages
Helpful Tools
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
RECT (Structures)
The RECT structure defines the coordinates of the upper-left and lower-right corners of a rectangle.

C# Signature:

    [Serializable, StructLayout(LayoutKind.Sequential)]
    public struct RECT {
      public int Left;
      public int Top;
      public int Right;
      public int Bottom;

      public RECT(int left_, int top_, int right_, int bottom_) {
        Left = left_;
        Top = top_;
        Right = right_;
        Bottom = bottom_;

      public int Height { get { return Bottom - Top + 1; } }
      public int Width { get { return Right - Left + 1; } }
      public Size Size { get { return new Size(Width, Height); } }

      public Point Location { get { return new Point(Left, Top); } }

      // Handy method for converting to a System.Drawing.Rectangle
      public Rectangle ToRectangle()
        { return Rectangle.FromLTRB(Left, Top, Right, Bottom); }

      public static RECT FromRectangle(Rectangle rectangle) {
        return new RECT(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom);

      public override int GetHashCode() {
        return Left ^ ((Top << 13) | (Top >> 0x13))
          ^ ((Width << 0x1a) | (Width >> 6))
          ^ ((Height << 7) | (Height >> 0x19));

      #region Operator overloads

      public static implicit operator Rectangle( RECT rect )
         return Rectangle.FromLTRB(rect.Left, rect.Top, rect.Right, rect.Bottom);

      public static implicit operator RECT( Rectangle rect )
         return new RECT(rect.Left, rect.Top, rect.Right, rect.Bottom);


VB .NET Signature:

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure RECT
        Public Left As Integer
        Public Top As Integer
        Public Right As Integer
        Public Bottom As Integer

        Public Sub New(ByVal pLeft As Integer, ByVal pTop As Integer, ByVal pRight As Integer, ByVal pBottom As Integer)
        left = pLeft
        top = pTop
        right = pRight
        bottom = pBottom
        End Sub

        Public ReadOnly Property Height() As Integer
            Return Bottom - Top + 1
        End Get
        End Property
        Public ReadOnly Property Width() As Integer
            Return Right - Left + 1
        End Get
        End Property
        Public ReadOnly Property Location() As Point
            Return New Point(Left, Top)
        End Get
        End Property
        Public ReadOnly Property Size() As Size
            Return New Size(Width, Height)
        End Get
        End Property

        Public Function ToRectangle() As Rectangle
        Return Rectangle.FromLTRB(Me.Left, Me.Top, Me.Right, Me.Bottom)
        End Function

        Public Shared Function ToRectangle(ByVal sourceRect As RECT) As Rectangle
        Return Rectangle.FromLTRB(sourceRect.Left, sourceRect.Top, sourceRect.Right, sourceRect.Bottom)
        End Function

        Public Shared Function FromRectangle(ByVal r As Rectangle) As RECT
        Return New RECT(r.Left, r.Top, r.Right, r.Bottom)
        End Function
    End Structure

User-Defined Types:



The Win32 RECT structure is not compatible with the .NET System.Drawing.Rectangle structure.

The RECT structure has left, top, right and bottom members,

but the System.Drawing.Rectangle structure has left, top, width and height members internally.

Tips & Tricks:

Please add some!

Sample Code:

Please add some!

Alternative Managed API:



Please edit this page!

Do you have...

  • helpful tips?
  • corrections to the existing content?
  • alternate definitions?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing any supporting types needed.

Access directly from VS:
Terms of Use
Find References
Show Printable Version