Size.Round Method (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.

Converts the specified SizeF structure to a Size structure by rounding the values of the SizeF structure to the nearest integer values.

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

public static Size Round(
	SizeF value
)

Parameters

value
Type: System.Drawing.SizeF

The SizeF structure to convert.

Return Value

Type: System.Drawing.Size

The Size structure this method converts to.

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.

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

}

.NET Framework
Available since 1.1
Return to top
Show: