Charles,
Where should exit code be placed: in the Closed event handler, or in the
OnClosed override function?
For classes that are derived from Form, I would put the exit code in the
overridden OnClosed method, remembering to call MyBase.OnClosed.
For objects that have a reference to the Form, I would put the exit code in
the Closed event handler code in that object.
In other words the Event is for classes not derived from the base class,
while the OnClosed is for derived classes. OnClosed also allows derived
classes to raise the event, or to supplement what happens when the event is
raised (pre or post processing).
For more details see:
http://msdn.microsoft.com/library/d.../cpgenref/html/cpconEventNamingGuidelines.asp
http://msdn.microsoft.com/library/d...s/cpgenref/html/cpconEventUsageGuidelines.asp
Note VB.NET's RaiseEvent itself will check for handlers attached to the
event, you can simply call RaiseEvent directly, you don't need to check for
Nothing as the above pages show.
Something like:
Public Class Class1
Private WithEvents m_base As Base
Public Sub New()
m_base = New Derived
End Sub
Private Sub Base_Changed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles m_base.Changed
' An aspect of the Base variable changed.
End Sub
End Class
Public Class Base
Public Event Changed As EventHandler
Private m_name As String
Protected Overridable Sub OnChanged(ByVal e As EventArgs)
RaiseEvent Changed(Me, e)
End Sub
Public Property Name() As String
Get
Return m_name
End Get
Set(ByVal value As String)
m_name = value
OnChanged(EventArgs.Empty)
End Set
End Property
End Class
Public Class Derived
Inherits Base
Private m_value As String
Public Property Value() As String
Get
Return m_value
End Get
Set(ByVal value As String)
m_value = value
OnChanged(EventArgs.Empty)
End Set
End Property
Protected Overrides Sub OnChanged(ByVal e As System.EventArgs)
' The Derived class wants to know if something changed
' In this example both Base & Derived raise this event!
' Do some thing before the event itself is raised
MyBase.OnChanged(e)
' Do some thing after the event itself is raised
End Sub
End Class
Hope this helps
Jay