Skip to main content
.NET Framework Class Library
Size..::.Round Method

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)
Syntax
Public Shared Function Round ( _
	value As SizeF _
) As Size
public static Size Round(
	SizeF value
)
public:
static Size Round(
	SizeF value
)
static member Round : 
        value:SizeF -> Size 

Parameters

value
Type: System.Drawing..::.SizeF
The SizeF structure to convert.

Return Value

Type: System.Drawing..::.Size
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.


Private Sub TruncateAndRoundSizes()

    ' Create a SizeF.
    Dim theSize As New SizeF(75.9, 75.9)

    ' Round the Size.
    Dim roundedSize As Size = Size.Round(theSize)

    ' Truncate the Size.
    Dim truncatedSize As Size = Size.Truncate(theSize)

    'Print out the values on two labels.
    Label1.Text = "Rounded size = " & roundedSize.ToString()
    Label2.Text = "Truncated size = " & truncatedSize.ToString

End Sub


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

}


void TruncateAndRoundSizes()
{
   // Create a SizeF.
   SizeF theSize = SizeF(75.9F,75.9F);

   // Round the Size.
   System::Drawing::Size roundedSize = ::Size::Round( theSize );

   // Truncate the Size.
   System::Drawing::Size truncatedSize = ::Size::Truncate( theSize );

   //Print out the values on two labels.
   Label1->Text = String::Format( "Rounded size = {0}", roundedSize );
   Label2->Text = String::Format( "Truncated size = {0}", truncatedSize );
}

Version Information

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Microsoft is conducting an online survey to understand your opinion of the MSDN Web site. If you choose to participate, the online survey will be presented to you when you leave the MSDN Web site.

Would you like to participate?