使用英语阅读

通过


Rectangle.Truncate(RectangleF) 方法

定义

通过截断 RectangleF 值,将指定的 RectangleF 转换为 Rectangle

public static System.Drawing.Rectangle Truncate (System.Drawing.RectangleF value);

参数

value
RectangleF

要转换的 RectangleF

返回

的截断值 Rectangle

示例

下面的代码示例演示如何使用 RoundTruncate 方法。 此示例旨在与 Windows 窗体一起使用。 将此代码粘贴到窗体中, RoundingAndTruncatingRectangles 并在处理窗体 Paint 的事件时调用 方法,作为 ePaintEventArgs传递。

private void RoundingAndTruncatingRectangles(PaintEventArgs e)
{

    // Construct a new RectangleF.
    RectangleF myRectangleF = 
        new RectangleF(30.6F, 30.7F, 40.8F, 100.9F);

    // Call the Round method.
    Rectangle roundedRectangle = Rectangle.Round(myRectangleF);

    // Draw the rounded rectangle in red.
    Pen redPen = new Pen(Color.Red, 4);
    e.Graphics.DrawRectangle(redPen, roundedRectangle);

    // Call the Truncate method.
    Rectangle truncatedRectangle = Rectangle.Truncate(myRectangleF);

    // Draw the truncated rectangle in white.
    Pen whitePen = new Pen(Color.White, 4);
    e.Graphics.DrawRectangle(whitePen, truncatedRectangle);

    // Dispose of the custom pens.
    redPen.Dispose();
    whitePen.Dispose();
}

适用于

产品 版本
.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