Edit

Share via


Size Constructors

Definition

Initializes a new instance of the Size structure from the specified Point.

Overloads

Size(Point)

Initializes a new instance of the Size structure from the specified Point structure.

Size(Int32, Int32)

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

Size(Point)

Source:
Size.cs
Source:
Size.cs
Source:
Size.cs

Initializes a new instance of the Size structure from the specified Point structure.

C#
public Size(System.Drawing.Point pt);

Parameters

pt
Point

The Point structure from which to initialize this Size 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

Size(Int32, Int32)

Source:
Size.cs
Source:
Size.cs
Source:
Size.cs

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

C#
public Size(int width, int height);

Parameters

width
Int32

The width component of the new Size.

height
Int32

The height component of the new Size.

Examples

The following code example demonstrates how to use the Point.Point and Size constructors and the System.Drawing.ContentAlignment enumeration. To run this example, paste this code into a Windows Form that contains a label named Label1 and call the InitializeLabel1 method in the form's constructor.

C#
private void InitializeLabel1()
{
    // Set a border.
    Label1.BorderStyle = BorderStyle.FixedSingle;

    // Set the size, constructing a size from two integers.
    Label1.Size = new Size(100, 50);

    // Set the location, constructing a point from a 32-bit integer
    // (using hexadecimal).
    Label1.Location = new Point(0x280028);

    // Set and align the text on the lower-right side of the label.
    Label1.TextAlign = ContentAlignment.BottomRight;
    Label1.Text = "Bottom Right Alignment";
}

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