Rectangle.Contains Methode

Definition

Bestimmt, ob der angegebene Punkt im rechteckigen Bereich liegt, der durch dieses Rectangle definiert ist.

Überlädt

Contains(Point)

Bestimmt, ob der angegebene Punkt in dieser Rectangle-Struktur enthalten ist.

Contains(Rectangle)

Bestimmt, ob der von rect dargestellte rechteckige Bereich vollständig in dieser Rectangle-Struktur enthalten ist.

Contains(Int32, Int32)

Bestimmt, ob der angegebene Punkt in dieser Rectangle-Struktur enthalten ist.

Contains(Point)

Quelle:
Rectangle.cs
Quelle:
Rectangle.cs
Quelle:
Rectangle.cs

Bestimmt, ob der angegebene Punkt in dieser Rectangle-Struktur enthalten ist.

public:
 bool Contains(System::Drawing::Point pt);
public readonly bool Contains (System.Drawing.Point pt);
public bool Contains (System.Drawing.Point pt);
member this.Contains : System.Drawing.Point -> bool
Public Function Contains (pt As Point) As Boolean

Parameter

pt
Point

Der zu überprüfende Point.

Gibt zurück

Diese Methode gibt true zurück, wenn der von pt dargestellte Punkt in dieser Rectangle-Struktur enthalten ist, andernfalls false.

Hinweise

Das enthaltende Rechteck muss für diese Methode normalisiert werden, um genaue Ergebnisse zurückzugeben.

Gilt für:

Contains(Rectangle)

Quelle:
Rectangle.cs
Quelle:
Rectangle.cs
Quelle:
Rectangle.cs

Bestimmt, ob der von rect dargestellte rechteckige Bereich vollständig in dieser Rectangle-Struktur enthalten ist.

public:
 bool Contains(System::Drawing::Rectangle rect);
public readonly bool Contains (System.Drawing.Rectangle rect);
public bool Contains (System.Drawing.Rectangle rect);
member this.Contains : System.Drawing.Rectangle -> bool
Public Function Contains (rect As Rectangle) As Boolean

Parameter

rect
Rectangle

Der zu überprüfende Rectangle.

Gibt zurück

Diese Methode gibt true zurück, wenn der von rect dargestellte rechteckige Bereich vollständig in dieser Rectangle-Struktur enthalten ist, andernfalls false.

Beispiele

Im folgenden Codebeispiel werden die Contains -Methode und die SystemPens -Klasse veranschaulicht. Dieses Beispiel ist für die Verwendung mit einem Windows Form-Formular konzipiert. Fügen Sie diesen Code in ein Formular ein, das eine Schaltfläche mit dem Namen Button1enthält, rufen Sie DrawFirstRectangle aus dem Konstruktor oder Load der Methode des Formulars auf, und ordnen Sie die Button1_Click -Methode dem -Ereignis der Schaltfläche Click zu.

private:
   [UIPermission(SecurityAction::Demand, Window=UIPermissionWindow::AllWindows)]
   void DrawFirstRectangle()
   {
      Rectangle rectangle1 = Rectangle(70,70,100,150);
      ControlPaint::DrawReversibleFrame( rectangle1, SystemColors::Highlight, FrameStyle::Thick );
   }

   void Button1_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      Rectangle rectangle1 = Rectangle(70,70,100,150);

      // Get the bounds of the screen.
      Rectangle screenRectangle = Screen::PrimaryScreen->Bounds;

      // Check to see if the rectangle is within the bounds of the screen.
      if ( screenRectangle.Contains( rectangle1 ) )
      {
         ControlPaint::DrawReversibleFrame( rectangle1, SystemColors::Highlight, FrameStyle::Thick );

         // Call the Offset method to move the rectangle.
         rectangle1.Offset( 20, 20 );

         // Draw the new, offset rectangle.
         ControlPaint::DrawReversibleFrame( rectangle1, SystemColors::Highlight, FrameStyle::Thick );
      }
   }
Rectangle rectangle1 = new Rectangle(70, 70, 100, 150);

private void DrawFirstRectangle()
{
    ControlPaint.DrawReversibleFrame(rectangle1, 
        SystemColors.Highlight, FrameStyle.Thick);
}

private void Button1_Click(object sender, EventArgs e)
{

    // Get the bounds of the screen.
    Rectangle screenRectangle = Screen.PrimaryScreen.Bounds;

    // Check to see if the rectangle is within the bounds of the screen.
    if (screenRectangle.Contains(rectangle1))

        // If so, erase the previous rectangle.
    {
        ControlPaint.DrawReversibleFrame(rectangle1, 
            SystemColors.Highlight, FrameStyle.Thick);

        // Call the Offset method to move the rectangle.
        rectangle1.Offset(20, 20);

        // Draw the new, offset rectangle.
        ControlPaint.DrawReversibleFrame(rectangle1, 
            SystemColors.Highlight, FrameStyle.Thick);
    }
}
Dim rectangle1 As New Rectangle(70, 70, 100, 150)

Private Sub DrawFirstRectangle()
    ControlPaint.DrawReversibleFrame(rectangle1, _
        SystemColors.Highlight, FrameStyle.Thick)
End Sub

Private Sub Button1_Click(ByVal sender As Object, _
    ByVal e As EventArgs) Handles Button1.Click

    ' Get the bounds of the screen.
    Dim screenRectangle As Rectangle = Screen.PrimaryScreen.Bounds

    ' Check to see if the rectangle is within the bounds of the screen.
    If (screenRectangle.Contains(rectangle1)) Then

        ' If so, erase the previous rectangle.
        ControlPaint.DrawReversibleFrame(rectangle1, _
            SystemColors.Highlight, FrameStyle.Thick)

        ' Call the Offset method to move the rectangle.
        rectangle1.Offset(20, 20)

        ' Draw the new, offset rectangle.
        ControlPaint.DrawReversibleFrame(rectangle1, _
            SystemColors.Highlight, FrameStyle.Thick)
    End If
End Sub

Hinweise

Das enthaltende Rechteck muss für diese Methode normalisiert werden, um genaue Ergebnisse zurückzugeben.

Gilt für:

Contains(Int32, Int32)

Quelle:
Rectangle.cs
Quelle:
Rectangle.cs
Quelle:
Rectangle.cs

Bestimmt, ob der angegebene Punkt in dieser Rectangle-Struktur enthalten ist.

public:
 bool Contains(int x, int y);
public readonly bool Contains (int x, int y);
public bool Contains (int x, int y);
member this.Contains : int * int -> bool
Public Function Contains (x As Integer, y As Integer) As Boolean

Parameter

x
Int32

Die x-Koordinate des Punktes, der überprüft werden soll.

y
Int32

Die y-Koordinate des Punktes, der überprüft werden soll.

Gibt zurück

Diese Methode gibt true zurück, wenn der von x und y definierte Punkt in dieser Rectangle-Struktur enthalten ist, andernfalls false.

Hinweise

Das enthaltende Rechteck muss für diese Methode normalisiert werden, um genaue Ergebnisse zurückzugeben.

Gilt für: