Size.Round(SizeF) Size.Round(SizeF) Size.Round(SizeF) Size.Round(SizeF) Method


藉由將 SizeF 結構的值捨入為最接近的整數值,來將指定的 Size 結構轉換為 SizeF 結構。Converts the specified SizeF structure to a Size structure by rounding the values of the SizeF structure to the nearest integer values.

 static System::Drawing::Size Round(System::Drawing::SizeF value);
public static System.Drawing.Size Round (System.Drawing.SizeF value);
static member Round : System.Drawing.SizeF -> System.Drawing.Size
Public Shared Function Round (value As SizeF) As Size


SizeF SizeF SizeF SizeF

要轉換的 SizeF 結構。The SizeF structure to convert.


這個方法轉換成的 SizeThe Size structure this method converts to.


下列程式碼範例示範如何使用Round靜態和Truncate方法Size, 將轉換SizeF成。The following code example demonstrates how to use static Round and Truncate methods to convert a SizeF to a Size. 這個範例是設計來與 Windows Forms 搭配使用。This example is designed to be used with Windows Forms. 若要執行此範例, 請將它貼到包含兩Label個名Label1Label2和之物件的表單中, 然後從表單的「函式」呼叫此方法。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.

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

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