Region.Dispose Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Släpper alla resurser som används av den här Region.
public:
virtual void Dispose();
public void Dispose();
abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit
Public Sub Dispose ()
Implementeringar
Exempel
I följande kodexempel visas Region konstruktorn och Exclude metoderna och Dispose .
Det här exemplet är utformat för att användas med Windows Forms. Klistra in koden i ett formulär och anropa FillRegionExcludingPath metoden när du hanterar formulärets Paint händelse och skicka e som 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
Kommentarer
Med anrop Dispose kan de resurser som används av detta Region omallokeras för andra ändamål.
Anropa Dispose när du är klar med .Region Metoden Dispose lämnar Region i ett oanvändbart tillstånd. När du har anropat Disposemåste du släppa alla referenser till så att Region skräpinsamlaren kan frigöra det minne som Region upptogs. Mer information finns i Rensa ohanterade resurser och implementera en rensningsmetod.
Note
Anropa Dispose alltid innan du släpper din senaste referens till Region. Annars frigörs inte de resurser som används förrän skräpinsamlaren Region anropar objektets Finalize -metod.