Edit

Share via


SizeF Constructors

Definition

Initializes a new instance of the SizeF structure from the specified existing SizeF structure.

Overloads

SizeF(PointF)

Initializes a new instance of the SizeF structure from the specified PointF structure.

SizeF(SizeF)

Initializes a new instance of the SizeF structure from the specified existing SizeF structure.

SizeF(Vector2)

Initializes a new instance of the SizeF struct from the specified Vector2.

SizeF(Single, Single)

Initializes a new instance of the SizeF structure from the specified dimensions.

SizeF(PointF)

Source:
SizeF.cs
Source:
SizeF.cs
Source:
SizeF.cs

Initializes a new instance of the SizeF structure from the specified PointF structure.

C#
public SizeF(System.Drawing.PointF pt);

Parameters

pt
PointF

The PointF structure from which to initialize this SizeF structure.

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

SizeF(SizeF)

Source:
SizeF.cs
Source:
SizeF.cs
Source:
SizeF.cs

Initializes a new instance of the SizeF structure from the specified existing SizeF structure.

C#
public SizeF(System.Drawing.SizeF size);

Parameters

size
SizeF

The SizeF structure from which to create the new SizeF structure.

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

SizeF(Vector2)

Source:
SizeF.cs
Source:
SizeF.cs
Source:
SizeF.cs

Initializes a new instance of the SizeF struct from the specified Vector2.

C#
public SizeF(System.Numerics.Vector2 vector);

Parameters

vector
Vector2

The source vector.

Applies to

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

SizeF(Single, Single)

Source:
SizeF.cs
Source:
SizeF.cs
Source:
SizeF.cs

Initializes a new instance of the SizeF structure from the specified dimensions.

C#
public SizeF(float width, float height);

Parameters

width
Single

The width component of the new SizeF structure.

height
Single

The height component of the new SizeF structure.

Examples

The following code example adds a shadow to a ListBox by using the following members:

This example is designed to be used with a Windows Form. To run this example, paste this code into a form and call the AddShadow method when handling the form's Paint event. Verify that the form contains a ListBox named listBox1.

C#
private void AddShadow(PaintEventArgs e)
{

    // Create two SizeF objects.
    SizeF shadowSize = listBox1.Size;
    SizeF addSize = new SizeF(10.5F, 20.8F);

    // Add them together and save the result in shadowSize.
    shadowSize = shadowSize + addSize;

    // Get the location of the ListBox and convert it to a PointF.
    PointF shadowLocation = listBox1.Location;

    // Add two points to get a new location.
    shadowLocation = shadowLocation + new Size(5, 5);

    // Create a rectangleF. 
    RectangleF rectFToFill = 
        new RectangleF(shadowLocation, shadowSize);

    // Create a custom brush using a semi-transparent color, and 
    // then fill in the rectangle.
    Color customColor = Color.FromArgb(50, Color.Gray);
    SolidBrush shadowBrush = new SolidBrush(customColor);
    e.Graphics.FillRectangles(shadowBrush, new RectangleF[]{rectFToFill});

    // Dispose of the brush.
    shadowBrush.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