RectangleF Constructors

Definition

Initializes a new instance of the RectangleF class with the specified location and size.

Overloads

RectangleF(Vector4)

Initializes a new instance of the RectangleF struct from the specified Vector4.

RectangleF(PointF, SizeF)

Initializes a new instance of the RectangleF class with the specified location and size.

RectangleF(Single, Single, Single, Single)

Initializes a new instance of the RectangleF class with the specified location and size.

RectangleF(Vector4)

Source:
RectangleF.cs
Source:
RectangleF.cs
Source:
RectangleF.cs

Initializes a new instance of the RectangleF struct from the specified Vector4.

C#
public RectangleF(System.Numerics.Vector4 vector);

Parameters

vector
Vector4

The source vector.

Applies to

.NET 10 and other versions
Product Versions
.NET 6, 7, 8, 9, 10

RectangleF(PointF, SizeF)

Source:
RectangleF.cs
Source:
RectangleF.cs
Source:
RectangleF.cs

Initializes a new instance of the RectangleF class with the specified location and size.

C#
public RectangleF(System.Drawing.PointF location, System.Drawing.SizeF size);

Parameters

location
PointF

A PointF that represents the upper-left corner of the rectangular region.

size
SizeF

A SizeF that represents the width and height of the rectangular region.

Examples

The following code example demonstrates how to use the Implicit, RectangleF, and Equality members. This example is designed for use with a Windows Form. Paste this code into a form and call the ConvertRectangleToRectangleF method when handling the form's Paint event, passing e as PaintEventArgs.

C#
private void ConvertRectangleToRectangleF(PaintEventArgs e)
{

    // Create a rectangle.
    Rectangle rectangle1 = new Rectangle(30, 40, 50, 100);

    // Convert it to a RectangleF.
    RectangleF convertedRectangle = rectangle1;

    // Create a new RectangleF.
    RectangleF rectangle2 = new RectangleF(new PointF(30.0F, 40.0F),
        new SizeF(50.0F, 100.0F));

    // Create a custom, partially transparent brush.
    SolidBrush redBrush = new SolidBrush(Color.FromArgb(40, Color.Red));

    // Compare the converted rectangle with the new one.  If they 
    // are equal draw and fill the rectangles on the form.
    if (convertedRectangle == rectangle2)
    {
        e.Graphics.FillRectangle(redBrush, rectangle2);
    }

    // Dispose of the custom brush.
    redBrush.Dispose();
}

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

RectangleF(Single, Single, Single, Single)

Source:
RectangleF.cs
Source:
RectangleF.cs
Source:
RectangleF.cs

Initializes a new instance of the RectangleF class with the specified location and size.

C#
public RectangleF(float x, float y, float width, float height);

Parameters

x
Single

The x-coordinate of the upper-left corner of the rectangle.

y
Single

The y-coordinate of the upper-left corner of the rectangle.

width
Single

The width of the rectangle.

height
Single

The height of the rectangle.

Examples

The following code example demonstrates how to use the RectangleF, Round and Truncate members. This example is designed for use with a Windows Form. Paste this code into a form and call the RoundingAndTruncatingRectangles method when handling the form's Paint event, passing e as PaintEventArgs.

C#
private void RoundingAndTruncatingRectangles(PaintEventArgs e)
{

    // Construct a new RectangleF.
    RectangleF myRectangleF = 
        new RectangleF(30.6F, 30.7F, 40.8F, 100.9F);

    // Call the Round method.
    Rectangle roundedRectangle = Rectangle.Round(myRectangleF);

    // Draw the rounded rectangle in red.
    Pen redPen = new Pen(Color.Red, 4);
    e.Graphics.DrawRectangle(redPen, roundedRectangle);

    // Call the Truncate method.
    Rectangle truncatedRectangle = Rectangle.Truncate(myRectangleF);

    // Draw the truncated rectangle in white.
    Pen whitePen = new Pen(Color.White, 4);
    e.Graphics.DrawRectangle(whitePen, truncatedRectangle);

    // Dispose of the custom pens.
    redPen.Dispose();
    whitePen.Dispose();
}

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1