Pen.Dispose Método

Definição

Libera todos os recursos usados por este Pen.Releases all resources used by this Pen.

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

Implementações

Exemplos

O exemplo de código a seguir demonstra os efeitos da definição das Width Propriedades e e LineJoin mostra como chamar o Dispose método para um Pen .The following code example demonstrates the effects of setting the Width and LineJoin properties, and shows how to call the Dispose method for a Pen.

Este exemplo foi projetado para ser usado com Windows Forms.This example is designed to be used with Windows Forms. Cole o código em um formulário e chame o ShowLineJoin método ao manipular o evento do formulário Paint , passando e como PaintEventArgs .Paste the code into a form and call the ShowLineJoin method when handling the form's Paint event, passing e as PaintEventArgs.

private:
   void ShowLineJoin( PaintEventArgs^ e )
   {
      // Create a new pen.
      Pen^ skyBluePen = gcnew Pen( Brushes::DeepSkyBlue );

      // Set the pen's width.
      skyBluePen->Width = 8.0F;

      // Set the LineJoin property.
      skyBluePen->LineJoin = System::Drawing::Drawing2D::LineJoin::Bevel;

      // Draw a rectangle.
      e->Graphics->DrawRectangle( skyBluePen, Rectangle(40,40,150,200) );

      //Dispose of the pen.
      delete skyBluePen;
   }
private void ShowLineJoin(PaintEventArgs e)
{

    // Create a new pen.
    Pen skyBluePen = new Pen(Brushes.DeepSkyBlue);

    // Set the pen's width.
    skyBluePen.Width = 8.0F;

    // Set the LineJoin property.
    skyBluePen.LineJoin = System.Drawing.Drawing2D.LineJoin.Bevel;

    // Draw a rectangle.
    e.Graphics.DrawRectangle(skyBluePen, 
        new Rectangle(40, 40, 150, 200));

    //Dispose of the pen.
    skyBluePen.Dispose();
}
Private Sub ShowLineJoin(ByVal e As PaintEventArgs)

    ' Create a new pen.
    Dim skyBluePen As New Pen(Brushes.DeepSkyBlue)

    ' Set the pen's width.
    skyBluePen.Width = 8.0F

    ' Set the LineJoin property.
    skyBluePen.LineJoin = Drawing2D.LineJoin.Bevel

    ' Draw a rectangle.
    e.Graphics.DrawRectangle(skyBluePen, _
        New Rectangle(40, 40, 150, 200))

    'Dispose of the pen.
    skyBluePen.Dispose()

End Sub

Comentários

DisposeA chamada permite que os recursos usados por ele Brush sejam realocados para outras finalidades.Calling Dispose allows the resources used by this Brush to be reallocated for other purposes.

Chame Dispose quando terminar de usar o Pen .Call Dispose when you are finished using the Pen. O Dispose método deixa o Pen em um estado inutilizável.The Dispose method leaves the Pen in an unusable state. Depois Dispose de chamar, você deve liberar todas as referências para o Pen , para que o coletor de lixo possa recuperar a memória que Pen estava ocupando.After calling Dispose, you must release all references to the Pen so the garbage collector can reclaim the memory that the Pen was occupying. Para obter mais informações, consulte limpando recursos não gerenciados e implementando um método Dispose.For more information, see Cleaning Up Unmanaged Resources and Implementing a Dispose Method.

Observação

Sempre chame Dispose antes de liberar sua última referência para o Pen .Always call Dispose before you release your last reference to the Pen. Caso contrário, os recursos que ele está usando não serão liberados até que o coletor de lixo chame o Pen método do objeto Finalize .Otherwise, the resources it is using will not be freed until the garbage collector calls the Pen object's Finalize method.

Aplica-se a