No, Atheist it is not if it is created using the "New" keyword. But I think I found a solution to it. Here is an example:
vb Code:
'This one must be disposed
Dim p As New Pen(Color.Red, 2)
e.Pen = p
p.Dispose()
'This one should not and can't be disposed.
e.Pen = Pens.Red
With the solution I cam up is this. In the paint event handler the developer should dispose the object if it is created using with the “New” keyword after he assigns the pen object to the “Pen” property otherwise he shouldn’t. And in my CustomPaintEventArgs I dispose the current pan and copy the user’s pen to the _pen member which its turn is disposed after it is used.
vb Code:
''' <summary>
''' Gets or sets the pen object that is used to draw the element.
''' </summary>
Public Overloads Property Pen() As Pen
Get
Return Me._pen
End Get
Set(ByVal value As Pen)
Me._pen.Dispose()
Me._pen = value.Clone()
End Set
End Property