Size.op_Equality-Methode
Überprüft, ob zwei Size-Strukturen gleich sind.
Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)
Syntax
'Declaration
Public Shared Operator = ( _
sz1 As Size, _
sz2 As Size _
) As Boolean
'Usage
Dim sz1 As Size
Dim sz2 As Size
Dim returnValue As Boolean
returnValue = (sz1 = sz2)
public static bool operator == (
Size sz1,
Size sz2
)
public:
static bool operator == (
Size sz1,
Size sz2
)
J# unterstützt keine überladenen Operatoren.
JScript unterstützt die Verwendung von überladenen Operatoren, aber nicht die Deklaration von neuen überladenen Operatoren.
Parameter
- sz1
Die Size-Struktur auf der linken Seite des Gleichheitsoperators.
- sz2
Die Size-Struktur auf der rechten Seite des Gleichheitsoperators.
Rückgabewert
true, wenn sz1 und sz2 dieselbe Breite und Höhe aufweisen, andernfalls false.
Beispiel
Im folgenden Codebeispiel werden unter Verwendung mehrerer für diese Typen definierter überladener Operatoren Punkte und Größen erstellt. Darüber hinaus wird die Verwendung der SystemPens-Klasse veranschaulicht.
Dieses Beispiel ist für die Verwendung mit Windows Forms vorgesehen. Erstellen Sie ein Formular, das eine Button mit dem Namen subtractButton
enthält. Fügen Sie den Code in das Formular ein, und rufen Sie in der Paint-Ereignisbehandlungsmethode des Formulars die CreatePointsAndSizes
-Methode auf, wobei Sie e als PaintEventArgs übergeben.
Private Sub CreatePointsAndSizes(ByVal e As PaintEventArgs)
' Create the starting point.
Dim startPoint As New Point(subtractButton.Size)
' Use the addition operator to get the end point.
Dim endPoint As Point = Point.op_Addition(startPoint, _
New Size(140, 150))
' Draw a line between the points.
e.Graphics.DrawLine(SystemPens.Highlight, startPoint, endPoint)
' Convert the starting point to a size and compare it to the
' subtractButton size.
Dim buttonSize As Size = Point.op_Explicit(startPoint)
If (Size.op_Equality(buttonSize, subtractButton.Size)) Then
' If the sizes are equal, tell the user.
e.Graphics.DrawString("The sizes are equal.", _
New Font(Me.Font, FontStyle.Italic), _
Brushes.Indigo, 10.0F, 65.0F)
End If
End Sub
private void CreatePointsAndSizes(PaintEventArgs e)
{
// Create the starting point.
Point startPoint = new Point(subtractButton.Size);
// Use the addition operator to get the end point.
Point endPoint = startPoint + new Size(140, 150);
// Draw a line between the points.
e.Graphics.DrawLine(SystemPens.Highlight, startPoint, endPoint);
// Convert the starting point to a size and compare it to the
// subtractButton size.
Size buttonSize = (Size)startPoint;
if (buttonSize == subtractButton.Size)
// If the sizes are equal, tell the user.
{
e.Graphics.DrawString("The sizes are equal.",
new Font(this.Font, FontStyle.Italic),
Brushes.Indigo, 10.0F, 65.0F);
}
}
void CreatePointsAndSizes( PaintEventArgs^ e )
{
// Create the starting point.
Point startPoint = Point(subtractButton->Size);
// Use the addition operator to get the end point.
Point endPoint = startPoint + System::Drawing::Size( 140, 150 );
// Draw a line between the points.
e->Graphics->DrawLine( SystemPens::Highlight, startPoint, endPoint );
// Convert the starting point to a size and compare it to the
// subtractButton size.
System::Drawing::Size buttonSize = (System::Drawing::Size)startPoint;
if ( buttonSize == subtractButton->Size )
{
e->Graphics->DrawString( "The sizes are equal.", gcnew System::Drawing::Font( this->Font,FontStyle::Italic ), Brushes::Indigo, 10.0F, 65.0F );
}
}
private void CreatePointsAndSizes(PaintEventArgs e)
{
// Create the starting point.
Point startPoint = new Point(subtractButton.get_Size());
// Use the addition operator to get the end point.
Point endPoint = Point.op_Addition(startPoint, new Size(140, 150));
// Draw a line between the points.
e.get_Graphics().DrawLine(SystemPens.get_Highlight(), startPoint,
endPoint);
// Convert the starting point to a size and compare it to the
// subtractButton size.
Size buttonSize = new Size(startPoint);
if (buttonSize.Equals(subtractButton.get_Size())) {
// If the sizes are equal, tell the user.
e.get_Graphics().DrawString("The sizes are equal.",
new Font(this.get_Font(), FontStyle.Italic),
Brushes.get_Indigo(), 10, 65);
}
} //CreatePointsAndSizes
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