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