Region.Dispose Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Rilascia tutte le risorse usate da questo Regionoggetto .
public:
virtual void Dispose();
public void Dispose();
abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit
Public Sub Dispose ()
Implementazioni
Esempio
Nell'esempio di codice seguente viene illustrato il Region costruttore e i Exclude metodi e Dispose .
Questo esempio è progettato per essere usato con Windows Form. Incollare il codice in una maschera e chiamare il FillRegionExcludingPath metodo quando si gestisce l'evento del Paint modulo, passando e come 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
Commenti
La chiamata Dispose consente di riallocare le risorse usate da questo Region oggetto per altri scopi.
Chiamare Dispose al termine dell'utilizzo di Region. Il Dispose metodo lascia l'oggetto Region in uno stato inutilizzabile. Dopo aver chiamato Dispose, è necessario rilasciare tutti i riferimenti a Region in modo che Region il Garbage Collector possa recuperare la memoria occupata da . Per altre informazioni, vedere Pulizia delle risorse non gestite e Implementazione di un metodo Dispose.
Note
Chiamare Dispose sempre prima di rilasciare l'ultimo Regionriferimento a . In caso contrario, le risorse in uso non verranno liberate finché il Garbage Collector non chiamerà il Region metodo dell'oggetto Finalize .