Pen.Dispose 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
이 Pen에서 사용하는 리소스를 모두 해제합니다.
public:
virtual void Dispose();
public void Dispose ();
abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit
Public Sub Dispose ()
구현
예제
다음 코드 예제에서는 설정 Width 의 효과 보여 줍니다는 및 LineJoin 속성 및 호출 하는 방법을 보여 줍니다는 Dispose 메서드에 대 한 합니다 Pen.
이 예제는 Windows Forms 함께 사용하도록 설계되었습니다. 폼에 코드를 붙여넣고 양식의 Paint 이벤트를 처리할 때 메서드를 호출 ShowLineJoin
하여 으로 PaintEventArgs전달합니다e
.
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
설명
를 호출 Dispose 하면 이 Brush 에 사용되는 리소스를 다른 용도로 다시 할당할 수 있습니다.
Dispose 사용을 마치면 Pen를 호출합니다. Dispose 메서드를 사용하면 Pen를 사용할 수 없게 됩니다. 호출한 후 Dispose에 대 한 모든 참조를 해제 해야 합니다 Pen 가비지 수집기에서 메모리를 회수할 수 있도록 하는 Pen 차지한 합니다. 자세한 내용은 관리 되지 않는 리소스 정리 하 고 Dispose 메서드 구현합니다.
참고
Dispose에 대한 마지막 참조를 해제하기 전에 반드시 Pen를 호출하십시오. 이렇게 하지 않으면 가비지 수집기가 Pen 개체의 Finalize
메서드를 호출할 때까지 사용 중인 리소스가 해제되지 않습니다.