Region.Dispose 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.
Libère toutes les ressources utilisées par ce Regionfichier .
public:
virtual void Dispose();
public void Dispose();
abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit
Public Sub Dispose ()
Implémente
Exemples
L’exemple de code suivant illustre le Region constructeur et les DisposeExclude méthodes.
Cet exemple est conçu pour être utilisé avec Windows Forms. Collez le code dans un formulaire et appelez la méthode lors de la FillRegionExcludingPath gestion de l’événement du Paint formulaire, en passant e en tant que PaintEventArgs.
private:
void FillRegionExcludingPath( PaintEventArgs^ e )
{
// Create the region using a rectangle.
System::Drawing::Region^ myRegion = gcnew System::Drawing::Region( Rectangle(20,20,100,100) );
// Create the GraphicsPath.
System::Drawing::Drawing2D::GraphicsPath^ path = gcnew System::Drawing::Drawing2D::GraphicsPath;
// Add a circle to the graphics path.
path->AddEllipse( 50, 50, 25, 25 );
// Exclude the circle from the region.
myRegion->Exclude( path );
// Retrieve a Graphics object from the form.
Graphics^ formGraphics = e->Graphics;
// Fill the region in blue.
formGraphics->FillRegion( Brushes::Blue, myRegion );
// Dispose of the path and region objects.
delete path;
delete myRegion;
}
private void FillRegionExcludingPath(PaintEventArgs e)
{
// Create the region using a rectangle.
Region myRegion = new Region(new Rectangle(20, 20, 100, 100));
// Create the GraphicsPath.
System.Drawing.Drawing2D.GraphicsPath path =
new System.Drawing.Drawing2D.GraphicsPath();
// Add a circle to the graphics path.
path.AddEllipse(50, 50, 25, 25);
// Exclude the circle from the region.
myRegion.Exclude(path);
// Retrieve a Graphics object from the form.
Graphics formGraphics = e.Graphics;
// Fill the region in blue.
formGraphics.FillRegion(Brushes.Blue, myRegion);
// Dispose of the path and region objects.
path.Dispose();
myRegion.Dispose();
}
Private Sub FillRegionExcludingPath(ByVal e As PaintEventArgs)
' Create the region using a rectangle.
Dim myRegion As New Region(New Rectangle(20, 20, 100, 100))
' Create the GraphicsPath.
Dim path As New System.Drawing.Drawing2D.GraphicsPath
' Add a circle to the graphics path.
path.AddEllipse(50, 50, 25, 25)
' Exclude the circle from the region.
myRegion.Exclude(path)
' Retrieve a Graphics object from the form.
Dim formGraphics As Graphics = e.Graphics
' Fill the region in blue.
formGraphics.FillRegion(Brushes.Blue, myRegion)
' Dispose of the path and region objects.
path.Dispose()
myRegion.Dispose()
End Sub
Remarques
L’appel Dispose permet aux ressources utilisées par cela Region d’être réaffectées à d’autres fins.
Appel Dispose lorsque vous avez terminé d’utiliser le Region. La Dispose méthode laisse l’état Region inutilisable. Après avoir appelé Dispose, vous devez libérer toutes les références au Region garbage collector afin que le garbage collector puisse récupérer la mémoire occupée Region . Pour plus d’informations, consultez Nettoyage des ressources non managées et implémentation d’une méthode Dispose.
Remarque
Appelez Dispose toujours avant de publier votre dernière référence au Region. Sinon, les ressources qu’il utilise ne seront pas libérées tant que le garbage collector n’appelle pas la Region méthode de l’objet Finalize .