Region.GetBounds(Graphics) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient une structure RectangleF qui représente un rectangle qui lie cet objet Region sur la surface de dessin d'un objet Graphics.
public:
System::Drawing::RectangleF GetBounds(System::Drawing::Graphics ^ g);
public System.Drawing.RectangleF GetBounds (System.Drawing.Graphics g);
member this.GetBounds : System.Drawing.Graphics -> System.Drawing.RectangleF
Public Function GetBounds (g As Graphics) As RectangleF
Paramètres
Retours
Structure RectangleF qui représente un rectangle englobant pour cet objet Region sur la surface de dessin spécifiée.
Exceptions
g
a la valeur null
.
Exemples
L’exemple de code suivant est conçu pour être utilisé avec Windows Forms et nécessite PaintEventArgse
, qui est un paramètre du Paint gestionnaire d’événements. Le code effectue les actions suivantes :
Crée un GraphicsPath et y ajoute une ellipse.
Remplit le chemin d’accès avec du bleu et le dessine à l’écran.
Crée une région qui utilise le GraphicsPath.
Obtient la zone non exclue de la région lorsqu’elle est combinée avec le deuxième rectangle.
Obtient le rectangle englobant de la région et le dessine à l’écran en rouge.
public:
void GetBoundsExample( PaintEventArgs^ e )
{
// Create a GraphicsPath and add an ellipse to it.
GraphicsPath^ myPath = gcnew GraphicsPath;
Rectangle ellipseRect = Rectangle(20,20,100,100);
myPath->AddEllipse( ellipseRect );
// Fill the path with blue and draw it to the screen.
SolidBrush^ myBrush = gcnew SolidBrush( Color::Blue );
e->Graphics->FillPath( myBrush, myPath );
// Create a region using the GraphicsPath.
System::Drawing::Region^ myRegion = gcnew System::Drawing::Region( myPath );
// Get the bounding rectangle for myRegion and draw it to the
// screen in Red.
RectangleF boundsRect = myRegion->GetBounds( e->Graphics );
e->Graphics->DrawRectangle( Pens::Red, Rectangle::Round( boundsRect ) );
}
public void GetBoundsExample(PaintEventArgs e)
{
// Create a GraphicsPath and add an ellipse to it.
GraphicsPath myPath = new GraphicsPath();
Rectangle ellipseRect = new Rectangle(20, 20, 100, 100);
myPath.AddEllipse(ellipseRect);
// Fill the path with blue and draw it to the screen.
SolidBrush myBrush = new SolidBrush(Color.Blue);
e.Graphics.FillPath(myBrush, myPath);
// Create a region using the GraphicsPath.
Region myRegion = new Region(myPath);
// Get the bounding rectangle for myRegion and draw it to the
// screen in Red.
RectangleF boundsRect = myRegion.GetBounds(e.Graphics);
e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(boundsRect));
}
Public Sub GetBoundsExample(ByVal e As PaintEventArgs)
' Create a GraphicsPath and add an ellipse to it.
Dim myPath As New GraphicsPath
Dim ellipseRect As New Rectangle(20, 20, 100, 100)
myPath.AddEllipse(ellipseRect)
' Fill the path with blue and draw it to the screen.
Dim myBrush As New SolidBrush(Color.Blue)
e.Graphics.FillPath(myBrush, myPath)
' Create a region using the GraphicsPath.
Dim myRegion As New [Region](myPath)
' Get the bounding rectangle for myRegion and draw it to the
' screen in Red.
Dim boundsRect As RectangleF = myRegion.GetBounds(e.Graphics)
e.Graphics.DrawRectangle(Pens.Red, Rectangle.Round(boundsRect))
End Sub
Remarques
La transformation actuelle du contexte graphique est utilisée pour calculer l’intérieur de la région sur la surface de dessin. Le rectangle englobant n’est pas toujours le plus petit rectangle englobant possible en fonction de la transformation en cours.
S’applique à
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de 2024, nous allons supprimer progressivement GitHub Issues comme mécanisme de commentaires pour le contenu et le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultezEnvoyer et afficher des commentaires pour