Freigeben über


Region.Dispose-Methode

Gibt alle von dieser Region verwendeten Ressourcen frei.

Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)

Syntax

'Declaration
Public Sub Dispose
'Usage
Dim instance As Region

instance.Dispose
public void Dispose ()
public:
virtual void Dispose () sealed
public final void Dispose ()
public final function Dispose ()

Rückgabewert

Diese Methode gibt keinen Wert zurück.

Hinweise

Durch einen Aufruf von Dispose können die von dieser Region verwendeten Ressourcen für andere Zwecke neu reserviert werden.

Rufen Sie Dispose auf, wenn Region nicht mehr benötigt wird. Die Dispose-Methode bewirkt, dass Region nicht mehr verwendet werden kann. Nach dem Aufruf von Dispose müssen Sie alle Verweise auf Region freigeben, sodass der von der Region belegte Speicher bei der Garbage Collection wieder zugänglich gemacht werden kann. Weitere Informationen finden Sie unter Bereinigen von nicht verwalteten Ressourcen und Implementieren einer Dispose-Methode.

Hinweis

Rufen Sie immer Dispose auf, bevor Sie den letzten Verweis auf die Region freigeben. Andernfalls bleiben die verwendeten Ressourcen reserviert, bis die Garbage Collection die Finalize-Methode des Region-Objekts aufruft.

Beispiel

Im folgenden Codebeispiel werden der Region-Konstruktor sowie die Exclude-Methode und die Dispose-Methode veranschaulicht.

Dieses Beispiel ist für die Verwendung mit Windows Forms vorgesehen. Fügen Sie den Code in ein Formular ein, und rufen Sie beim Behandeln des Paint-Ereignisses des Formulars die FillRegionExcludingPath-Methode auf, wobei Sie e als PaintEventArgs übergeben.

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
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:
   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.get_Graphics();

    // Fill the region in blue.
    formGraphics.FillRegion(Brushes.get_Blue(), myRegion);

    // Dispose of the path and region objects.
    path.Dispose();
    myRegion.Dispose();
} //FillRegionExcludingPath

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

Region-Klasse
Region-Member
System.Drawing-Namespace