Region.Dispose Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Libera todos los recursos usados por este Region.
public:
virtual void Dispose();
public void Dispose();
abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit
Public Sub Dispose ()
Implementaciones
Ejemplos
En el ejemplo de código siguiente se muestra el Region constructor y los Exclude métodos y Dispose .
Este ejemplo está diseñado para usarse con Windows Forms. Pegue el código en un formulario y llame al FillRegionExcludingPath método al controlar el evento del Paint formulario, pasando e como 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
Comentarios
La llamada Dispose permite reasignar los recursos usados por este Region para otros fines.
Llame a Dispose cuando haya terminado de usar .Region El Dispose método deja en Region un estado inutilizable. Después de llamar a Dispose, debe liberar todas las referencias a Region para que el recolector de elementos no utilizados pueda reclamar la memoria que Region estaba ocupando. Para obtener más información, consulte Limpieza de recursos no administrados e Implementación de un método Dispose.
Nota:
Dispose Llame siempre antes de liberar la última referencia a .Region De lo contrario, los recursos que usa no se liberarán hasta que el recolector de elementos no utilizados llame al Region método del Finalize objeto.