Rectangle.Round(RectangleF) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
藉由將 RectangleF 值捨入為最接近的整數值,來將指定的 RectangleF 轉換為 Rectangle。
public:
static System::Drawing::Rectangle Round(System::Drawing::RectangleF value);
public static System.Drawing.Rectangle Round (System.Drawing.RectangleF value);
static member Round : System.Drawing.RectangleF -> System.Drawing.Rectangle
Public Shared Function Round (value As RectangleF) As Rectangle
參數
- value
- RectangleF
要轉換的 RectangleF。
傳回
Rectangle 的四捨五入整數值。
範例
下列程式代碼範例示範如何使用 Round 和 Truncate 方法。 此範例的設計目的是要與 Windows Form 搭配使用。 將此程式代碼貼到表單中,並在處理表單的事件時呼叫 RoundingAndTruncatingRectangles
方法,並e
傳遞為 PaintEventArgs。Paint
private:
void RoundingAndTruncatingRectangles( PaintEventArgs^ e )
{
// Construct a new RectangleF.
RectangleF myRectangleF = 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 = gcnew Pen( Color::Red,4.0f );
e->Graphics->DrawRectangle( redPen, roundedRectangle );
// Call the Truncate method.
Rectangle truncatedRectangle = Rectangle::Truncate( myRectangleF );
// Draw the truncated rectangle in white.
Pen^ whitePen = gcnew Pen( Color::White,4.0f );
e->Graphics->DrawRectangle( whitePen, truncatedRectangle );
// Dispose of the custom pens.
delete redPen;
delete whitePen;
}
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();
}
Private Sub RoundingAndTruncatingRectangles( _
ByVal e As PaintEventArgs)
' Construct a new RectangleF.
Dim myRectangleF As New RectangleF(30.6F, 30.7F, 40.8F, 100.9F)
' Call the Round method.
Dim roundedRectangle As Rectangle = Rectangle.Round(myRectangleF)
' Draw the rounded rectangle in red.
Dim redPen As New Pen(Color.Red, 4)
e.Graphics.DrawRectangle(redPen, roundedRectangle)
' Call the Truncate method.
Dim truncatedRectangle As Rectangle = _
Rectangle.Truncate(myRectangleF)
' Draw the truncated rectangle in white.
Dim whitePen As New Pen(Color.White, 4)
e.Graphics.DrawRectangle(whitePen, truncatedRectangle)
' Dispose of the custom pens.
redPen.Dispose()
whitePen.Dispose()
End Sub