Search Results for

    Show / Hide Table of Contents

    Class Rectangle

    A universally compatible Rectangle for .NET 7, .NET 6, .NET 5, and .NET Core. As well as compatibility with Windows, NanoServer, IIS, macOS, Mobile, Xamarin, iOS, Android, Google Compute, Azure, AWS, and Linux.

    Works nicely with popular Image Rectangle such as System.Drawing.Rectangle, SkiaSharp.SKRect, SixLabors.ImageSharp.Rectangle, Microsoft.Maui.Graphics.Rect.

    Implicit casting means that using this class to input and output Rectangle from public APIs gives full compatibility to all Rectangle type fully supported by Microsoft.

    Inheritance
    System.Object
    Rectangle
    Namespace: IronSoftware.Drawing
    Assembly: IronSoftware.Drawing.Common.dll
    Syntax
    public class Rectangle : Object

    Constructors

    Rectangle()

    Construct a new Rectangle.

    Declaration
    public Rectangle()
    See Also
    Rectangle

    Rectangle(Point, Size, MeasurementUnits)

    Initializes a new instance of the Rectangle struct.

    Declaration
    public Rectangle(Point point, Size size, MeasurementUnits units)
    Parameters
    Type Name Description
    Point point

    The Point which specifies the rectangles point in a two-dimensional plane.

    Size size

    The IronSoftware.Drawing.Rectangle.Size which specifies the rectangles height and width.

    MeasurementUnits units

    The measurement unit of this Rectangle

    See Also
    Rectangle

    Rectangle(Int32, Int32, Int32, Int32, MeasurementUnits)

    Construct a new Rectangle.

    Declaration
    public Rectangle(int x, int y, int width, int height, MeasurementUnits units)
    Parameters
    Type Name Description
    System.Int32 x

    The x-coordinate of the upper-left corner of this Rectangle

    System.Int32 y

    The y-coordinate of the upper-left corner of this Rectangle

    System.Int32 width

    The width of this Rectangle

    System.Int32 height

    The height of this Rectangle

    MeasurementUnits units

    The measurement unit of this Rectangle

    See Also
    Rectangle

    Properties

    Bottom

    Gets the y-coordinate of the bottom edge of this Rectangle.

    Declaration
    public int Bottom { get; }
    Property Value
    Type Description
    System.Int32

    Height

    The height of this Rectangle. The default is 0.

    Declaration
    public int Height { get; set; }
    Property Value
    Type Description
    System.Int32

    Left

    Gets the x-coordinate of the left edge of this Rectangle.

    Declaration
    public int Left { get; }
    Property Value
    Type Description
    System.Int32

    Right

    Gets the x-coordinate of the right edge of this Rectangle.

    Declaration
    public int Right { get; }
    Property Value
    Type Description
    System.Int32

    Top

    Gets the y-coordinate of the top edge of this Rectangle.

    Declaration
    public int Top { get; }
    Property Value
    Type Description
    System.Int32

    Units

    The measurement unit of this Rectangle. The default is Pixels

    Declaration
    public MeasurementUnits Units { get; set; }
    Property Value
    Type Description
    MeasurementUnits

    Width

    The width of this Rectangle. The default is 0.

    Declaration
    public int Width { get; set; }
    Property Value
    Type Description
    System.Int32

    X

    The x-coordinate of the upper-left corner of this Rectangle. The default is 0.

    Declaration
    public int X { get; set; }
    Property Value
    Type Description
    System.Int32

    Y

    The y-coordinate of the upper-left corner of this Rectangle. The default is 0.

    Declaration
    public int Y { get; set; }
    Property Value
    Type Description
    System.Int32

    Methods

    Contains(Int32, Int32)

    Determines if the specified point is contained within the rectangular region defined by this Rectangle.

    Declaration
    public bool Contains(int x, int y)
    Parameters
    Type Name Description
    System.Int32 x

    The x-coordinate of the given point.

    System.Int32 y

    The y-coordinate of the given point.

    Returns
    Type Description
    System.Boolean

    ConvertTo(MeasurementUnits, Int32)

    Convert this rectangle to the specified units of measurement using the specified DPI

    Declaration
    public Rectangle ConvertTo(MeasurementUnits toUnits, int dpi = 96)
    Parameters
    Type Name Description
    MeasurementUnits toUnits

    Unit of measurement

    System.Int32 dpi

    DPI (Dots per inch) for conversion

    Returns
    Type Description
    Rectangle

    A new rectangle which uses the desired units of measurement

    Exceptions
    Type Condition
    System.NotImplementedException

    Conversion not implemented

    Operators

    Implicit(Rectangle to RectangleF)

    Implicitly casts to RectangleF objects from Rectangle.

    When your .NET Class methods use Rectangle as parameters and return types, you now automatically support RectangleF as well.

    Declaration
    public static implicit operator RectangleF(Rectangle Rectangle)
    Parameters
    Type Name Description
    Rectangle Rectangle

    Rectangle is explicitly cast to a RectangleF.

    Returns
    Type Description
    RectangleF

    Implicit(Rectangle to Rect)

    Implicitly casts to Microsoft.Maui.Graphics.Rect objects from Rectangle.

    When your .NET Class methods use Rectangle as parameters and return types, you now automatically support Microsoft.Maui.Graphics.Rect as well.

    Declaration
    public static implicit operator Rect(Rectangle Rectangle)
    Parameters
    Type Name Description
    Rectangle Rectangle

    Rectangle is explicitly cast to a Microsoft.Maui.Graphics.Rect.

    Returns
    Type Description
    Microsoft.Maui.Graphics.Rect

    Implicit(Rectangle to RectF)

    Implicitly casts to Microsoft.Maui.Graphics.RectF objects from Rectangle.

    When your .NET Class methods use Rectangle as parameters and return types, you now automatically support Microsoft.Maui.Graphics.RectF as well.

    Declaration
    public static implicit operator RectF(Rectangle Rectangle)
    Parameters
    Type Name Description
    Rectangle Rectangle

    Rectangle is explicitly cast to a Microsoft.Maui.Graphics.RectF.

    Returns
    Type Description
    Microsoft.Maui.Graphics.RectF

    Implicit(Rectangle to Rectangle)

    Implicitly casts to SixLabors.ImageSharp.Rectangle objects from Rectangle.

    When your .NET Class methods use Rectangle as parameters and return types, you now automatically support SixLabors.ImageSharp.Rectangle as well.

    Declaration
    public static implicit operator Rectangle(Rectangle Rectangle)
    Parameters
    Type Name Description
    Rectangle Rectangle

    Rectangle is explicitly cast to a SixLabors.ImageSharp.Rectangle.

    Returns
    Type Description
    SixLabors.ImageSharp.Rectangle

    Implicit(Rectangle to RectangleF)

    Implicitly casts to SixLabors.ImageSharp.RectangleF objects from Rectangle.

    When your .NET Class methods use Rectangle as parameters and return types, you now automatically support SixLabors.ImageSharp.RectangleF as well.

    Declaration
    public static implicit operator RectangleF(Rectangle Rectangle)
    Parameters
    Type Name Description
    Rectangle Rectangle

    Rectangle is explicitly cast to a SixLabors.ImageSharp.RectangleF.

    Returns
    Type Description
    SixLabors.ImageSharp.RectangleF

    Implicit(Rectangle to SKRect)

    Implicitly casts to SkiaSharp.SKRect objects from Rectangle.

    When your .NET Class methods use Rectangle as parameters and return types, you now automatically support SkiaSharp.SKRect as well.

    Declaration
    public static implicit operator SKRect(Rectangle Rectangle)
    Parameters
    Type Name Description
    Rectangle Rectangle

    Rectangle is explicitly cast to a SkiaSharp.SKRect.

    Returns
    Type Description
    SkiaSharp.SKRect

    Implicit(Rectangle to SKRectI)

    Implicitly casts to SkiaSharp.SKRectI objects from Rectangle.

    When your .NET Class methods use Rectangle as parameters and return types, you now automatically support SkiaSharp.SKRectI as well.

    Declaration
    public static implicit operator SKRectI(Rectangle Rectangle)
    Parameters
    Type Name Description
    Rectangle Rectangle

    Rectangle is explicitly cast to a SkiaSharp.SKRectI.

    Returns
    Type Description
    SkiaSharp.SKRectI

    Implicit(Rectangle to Rectangle)

    Implicitly casts to System.Drawing.Rectangle objects from Rectangle.

    When your .NET Class methods use Rectangle as parameters and return types, you now automatically support Rectangle as well.

    Declaration
    public static implicit operator Rectangle(Rectangle Rectangle)
    Parameters
    Type Name Description
    Rectangle Rectangle

    Rectangle is explicitly cast to a System.Drawing.Rectangle.

    Returns
    Type Description
    System.Drawing.Rectangle

    Implicit(Rect to Rectangle)

    Implicitly casts Microsoft.Maui.Graphics.Rect objects to Rectangle.

    When your .NET Class methods use Rectangle as parameters and return types, you now automatically support Microsoft.Maui.Graphics.Rect as well.

    Declaration
    public static implicit operator Rectangle(Rect rectangle)
    Parameters
    Type Name Description
    Microsoft.Maui.Graphics.Rect rectangle

    Microsoft.Maui.Graphics.Rect will automatically be casted to Rectangle.

    Returns
    Type Description
    Rectangle

    Implicit(RectF to Rectangle)

    Implicitly casts Microsoft.Maui.Graphics.RectF objects to Rectangle.

    When your .NET Class methods use Rectangle as parameters and return types, you now automatically support Microsoft.Maui.Graphics.RectF as well.

    Declaration
    public static implicit operator Rectangle(RectF rectangle)
    Parameters
    Type Name Description
    Microsoft.Maui.Graphics.RectF rectangle

    Microsoft.Maui.Graphics.RectF will automatically be casted to Rectangle.

    Returns
    Type Description
    Rectangle

    Implicit(Rectangle to Rectangle)

    Implicitly casts SixLabors.ImageSharp.Rectangle objects to Rectangle.

    When your .NET Class methods use Rectangle as parameters and return types, you now automatically support SixLabors.ImageSharp.Rectangle as well.

    Declaration
    public static implicit operator Rectangle(Rectangle rectangle)
    Parameters
    Type Name Description
    SixLabors.ImageSharp.Rectangle rectangle

    SixLabors.ImageSharp.Rectangle will automatically be casted to Rectangle.

    Returns
    Type Description
    Rectangle

    Implicit(RectangleF to Rectangle)

    Implicitly casts SixLabors.ImageSharp.RectangleF objects to Rectangle.

    When your .NET Class methods use Rectangle as parameters and return types, you now automatically support SixLabors.ImageSharp.RectangleF as well.

    Declaration
    public static implicit operator Rectangle(RectangleF rectangle)
    Parameters
    Type Name Description
    SixLabors.ImageSharp.RectangleF rectangle

    SixLabors.ImageSharp.RectangleF will automatically be casted to Rectangle.

    Returns
    Type Description
    Rectangle

    Implicit(SKRect to Rectangle)

    Implicitly casts SkiaSharp.SKRect objects to Rectangle.

    When your .NET Class methods use Rectangle as parameters and return types, you now automatically support SkiaSharp.SKRect as well.

    Declaration
    public static implicit operator Rectangle(SKRect sKRect)
    Parameters
    Type Name Description
    SkiaSharp.SKRect sKRect

    SkiaSharp.SKRect will automatically be casted to Rectangle.

    Returns
    Type Description
    Rectangle

    Implicit(SKRectI to Rectangle)

    Implicitly casts SkiaSharp.SKRectI objects to Rectangle.

    When your .NET Class methods use Rectangle as parameters and return types, you now automatically support SkiaSharp.SKRectI as well.

    Declaration
    public static implicit operator Rectangle(SKRectI sKRectI)
    Parameters
    Type Name Description
    SkiaSharp.SKRectI sKRectI

    SkiaSharp.SKRectI will automatically be casted to Rectangle.

    Returns
    Type Description
    Rectangle

    Implicit(Rectangle to Rectangle)

    Implicitly casts System.Drawing.Rectangle objects to Rectangle.

    When your .NET Class methods use Rectangle as parameters and return types, you now automatically support Rectangle as well.

    Declaration
    public static implicit operator Rectangle(Rectangle rectangle)
    Parameters
    Type Name Description
    System.Drawing.Rectangle rectangle

    System.Drawing.Rectangle will automatically be casted to Rectangle.

    Returns
    Type Description
    Rectangle
    ☀
    ☾
    Downloads
    • Download with Nuget
    In This Article
    Back to top
    Install with Nuget
    Want to deploy IronDrawing to a live project for FREE?
    What’s included?
    30 days of fully-functional product
    Test and share in a live environment
    No watermarks in production
    Get your free 30-day Trial Key instantly.
    No credit card or account creation required
    Your Trial License Key has been emailed to you.
    Download IronDrawing free to apply
    your Trial Licenses Key
    Install with NuGet View Licenses
    Licenses from $499. Have a question? Get in touch.