Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


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

RECT (Structures)
 
.
Summary
This structure defines the coordinates of the upper-left and lower-right corners of a rectangle. With the ToRectangle method, we can return one System.Drawing.Rectangle structure instance for this 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)
   {
     this.left = left;
     this.top = top;
     this.right = right;
     this.bottom = bottom;
   }

   public int Height
   {
      get { return (bottom - top); }
   }

   public int Width
   {
      get { return (right - left); }
   }

   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);
   }
}

VB Definition:

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

    Public Overrides Function ToString() As String
        ToString = String.Format("({0},{1})-({2},{3})", Left, Top, Right, Bottom)
    End Function

    'Conversion to rectangle
    Public ReadOnly Property Rectangle() As Rectangle
        Get
        Return Rectangle.FromLTRB(Left, Top, Right, Bottom)
        End Get
    End Property
    End Structure

Notes:

This can be used when a PInvoke signature requires a "Win32 Rectangle" otherwise you should be using System.Drawing.Rectangle. Note that a Win32 rectangle is specified by two opposite corners (LTRB), while a .NET rectangle is specified by one corner and width/height (LTWH).

Documentation
RECT on MSDN

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 PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions