RectangleF Constructor (PointF, SizeF)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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

Namespace:   System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)

public RectangleF(
	PointF location,
	SizeF size
)

Parameters

location
Type: System.Drawing.PointF

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

size
Type: System.Drawing.SizeF

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

The following code example demonstrates how to use the Implicit(Rectangle to RectangleF), 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.

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

.NET Framework
Available since 1.1
Return to top
Show: