Size.Round(SizeF) 方法

定义

通过将 SizeF 结构的值舍入到最近的较大整数值,将指定的 SizeF 结构转换为 Size 结构。

public:
 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

参数

value
SizeF

要转换的 SizeF 结构。

返回

由此方法转换得到的 Size 结构。

示例

下面的代码示例演示如何使用静态 Round 和 方法将 转换为 SizeFSizeTruncate 此示例旨在与 Windows 窗体 一起使用。 若要运行此示例,请将其粘贴到包含两 Label 个名为 Label1Label2的对象的窗体中,然后从窗体的构造函数调用此方法。

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

适用于