Size.Truncate(SizeF) Method

Definition

Converts the specified SizeF structure to a Size structure by truncating the values of the SizeF structure to the next lower integer values.

C#
public static System.Drawing.Size Truncate(System.Drawing.SizeF value);

Parameters

value
SizeF

The SizeF structure to convert.

Returns

The Size structure this method converts to.

Examples

The following code example demonstrates how to use static Round and Truncate methods to convert a SizeF to a Size. This example is designed to be used with Windows Forms. To run this example, paste it into a form that contains two Label objects named Label1 and Label2, and then call this method from the form's constructor.

C#
private void TruncateAndRoundSizes()
{

    // Create a SizeF.
    SizeF theSize = new SizeF(75.9F, 75.9F);

    // Round the Size.
    Size roundedSize = Size.Round(theSize);

    // Truncate the Size.
    Size truncatedSize = Size.Truncate(theSize);

    //Print out the values on two labels.
    Label1.Text = "Rounded size = "+roundedSize.ToString();
    Label2.Text = "Truncated size = "+truncatedSize.ToString();
}

Applies to

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
.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