Rectangle.Round-Methode
Konvertiert das angegebene RectangleF in ein Rectangle, indem die RectangleF-Werte auf die nächste ganze Zahl gerundet werden.
Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)
Syntax
'Declaration
Public Shared Function Round ( _
value As RectangleF _
) As Rectangle
'Usage
Dim value As RectangleF
Dim returnValue As Rectangle
returnValue = Rectangle.Round(value)
public static Rectangle Round (
RectangleF value
)
public:
static Rectangle Round (
RectangleF value
)
public static Rectangle Round (
RectangleF value
)
public static function Round (
value : RectangleF
) : Rectangle
Parameter
- value
Das zu konvertierende RectangleF.
Rückgabewert
Ein Rectangle.
Beispiel
Im folgenden Codebeispiel wird die Verwendung der Round-Methode und der Truncate-Methode veranschaulicht. Dieses Beispiel ist für die Verwendung mit einem Windows Form vorgesehen. Fügen Sie diesen Code in ein Formular ein, und rufen Sie beim Behandeln des Paint-Ereignisses des Formulars die RoundingAndTruncatingRectangles
-Methode auf, wobei Sie e als PaintEventArgs übergeben.
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
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:
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;
}
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0
Siehe auch
Referenz
Rectangle-Struktur
Rectangle-Member
System.Drawing-Namespace