Język

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 przedstawiono Region konstruktor i Exclude metody i Dispose .

Ten przykład został zaprojektowany do użycia z formularzami systemu Windows. Wklej kod do formularza i wywołaj FillRegionExcludingPath metodę podczas obsługi zdarzenia formularza Paint , przekazując e 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 przeniesienie zasobów używanych przez tę Region funkcję do innych celów.

Wywołaj metodę Dispose po zakończeniu korzystania z elementu Region. Metoda Dispose pozostawia Region w stanie bezużytecznym. Po wywołaniu metody Disposenależy zwolnić wszystkie odwołania do Region modułu , aby moduł odśmiecania pamięci mógł odzyskać pamięć zajmowaną przez Region element . Aby uzyskać więcej informacji, zobacz Oczyszczanie zasobów niezarządzanych i Implementowanie metody Dispose.

Note

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, dopóki moduł odśmiecający elementy bezużyteczne wywoła Region metodę obiektu Finalize .

Dotyczy