Region.Dispose Méthode

Définition

Libère toutes les ressources utilisées par ce Region.

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 Exclude méthodes et Dispose .

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 comme 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 de réallouer les ressources utilisées à Region d’autres fins.

Appelez la méthode Dispose une fois que vous avez terminé d'utiliser Region. La méthode Dispose rend le Region inutilisable. Après avoir appelé Dispose, vous devez libérer toutes les références à afin Region que le garbage collector puisse récupérer la mémoire que le Region occupait. Pour plus d’informations, consultez Nettoyage des ressources non managées et Implémentation d’une méthode Dispose.

Notes

Appelez toujours Dispose avant de libérer votre dernière référence à Region. Sinon, les ressources utilisées ne seront pas libérées tant que le garbage collector n'aura pas appelé la méthode Region de l'objet Finalize.

S’applique à