Rectangle.Contains Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Determina se il punto specificato è contenuto nell'area rettangolare definita da questo Rectangleoggetto .
Overload
| Nome | Descrizione |
|---|---|
| Contains(Point) |
Determina se il punto specificato è contenuto all'interno di questa Rectangle struttura. |
| Contains(Rectangle) |
Determina se l'area rettangolare rappresentata da |
| Contains(Int32, Int32) |
Determina se il punto specificato è contenuto all'interno di questa Rectangle struttura. |
Contains(Point)
Determina se il punto specificato è contenuto all'interno di questa Rectangle struttura.
public:
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
Parametri
Valori restituiti
Questo metodo restituisce true se il punto rappresentato da pt è contenuto all'interno di questa Rectangle struttura; in caso contrario false, .
Commenti
Il rettangolo contenitore deve essere normalizzato affinché questo metodo restituisca risultati accurati.
Si applica a
Contains(Rectangle)
Determina se l'area rettangolare rappresentata da rect è interamente contenuta all'interno di questa Rectangle struttura.
public:
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
Parametri
Valori restituiti
Questo metodo restituisce true se l'area rettangolare rappresentata da rect è interamente contenuta all'interno di questa Rectangle struttura; in caso contrario false, .
Esempio
Nell'esempio di codice seguente viene illustrato il Contains metodo e la SystemPens classe . Questo esempio è progettato per l'uso con un modulo Windows. Incollare questo codice in un modulo contenente un pulsante denominato Button1, chiamare DrawFirstRectangle dal costruttore o Load dal metodo del modulo e associare il Button1_Click metodo all'evento del Click pulsante.
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
Commenti
Il rettangolo contenitore deve essere normalizzato affinché questo metodo restituisca risultati accurati.
Si applica a
Contains(Int32, Int32)
Determina se il punto specificato è contenuto all'interno di questa Rectangle struttura.
public:
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
Parametri
- x
- Int32
Coordinata x del punto da testare.
- y
- Int32
Coordinata y del punto da testare.
Valori restituiti
Questo metodo restituisce true se il punto definito da x e y è contenuto all'interno di questa Rectangle struttura; in caso contrario false, .
Commenti
Il rettangolo contenitore deve essere normalizzato affinché questo metodo restituisca risultati accurati.