Share via


Region.Dispose Metoda

Definice

Uvolní všechny prostředky používané tímto Regionnástrojem .

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

Implementuje

Příklady

Následující příklad kódu ukazuje Region konstruktor a Exclude metody a .Dispose

Tento příklad je navržený pro použití s model Windows Forms. Vložte kód do formuláře a při zpracování události formuláře Paint volejte FillRegionExcludingPath metodu, která se předává 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

Poznámky

Volání Dispose umožňuje přerozdělit prostředky, které tento Region nástroj používá, pro jiné účely.

Až budete hotovi s použitím příkazu , zavolejte Dispose .Region Metoda Dispose ponechá objekt Region v nepoužitelném stavu. Po volání Disposemusíte uvolnit všechny odkazy na Region objekt, aby systém uvolňování paměti mohl uvolnit paměť, kterou Region zabírala. Další informace najdete v tématech Čištění nespravovaných prostředků a Implementace metody Dispose.

Poznámka

Dispose Před uvolněním posledního odkazu na Region. Jinak prostředky, které používá, nebudou uvolněny, dokud systém uvolňování paměti nezavolá metodu objektu RegionFinalize .

Platí pro