Region.Dispose Metoda

Definicja

Zwalnia wszystkie zasoby używane przez ten Regionprogram .

public:
 virtual void Dispose();
public void Dispose ();
abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit
Public Sub Dispose ()

Implementuje

Przykłady

W poniższym przykładzie kodu pokazano Region konstruktor i Exclude metody i Dispose .

Ten przykład jest przeznaczony do użycia z Windows Forms. Wklej kod do formularza i wywołaj FillRegionExcludingPath metodę podczas obsługi zdarzenia formularza Paint , przekazując e go jako 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

Uwagi

Wywołanie Dispose umożliwia przydział zasobów używanych przez tę Region funkcję do innych celów.

Po Dispose zakończeniu połączenia użyj polecenia Region. Metoda Dispose pozostawia Region obiekt w stanie bezużytecznym. Po wywołaniu Disposemetody należy zwolnić wszystkie odwołania do Region modułu , aby moduł odśmiecania pamięci mógł odzyskać pamięć zajmowaną przez Region moduł. Aby uzyskać więcej informacji, zobacz Oczyszczanie niezarządzanych zasobów i Implementowanie metody Dispose.

Uwaga

Przed wydaniem ostatniego odwołania do elementu należy zawsze wywołać metodę DisposeRegion. W przeciwnym razie zasoby, których używasz, nie zostaną zwolnione do momentu wywołania Region metody obiektu przez moduł odśmiecowania Finalize pamięci.

Dotyczy