Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27154

Raising events in base class from derived class?

$
0
0
Hi VBForums, can someone tell me how to accomplish this functionality correctly?

Example:

Public Class BaseClass
Public Property Progress
Public Event UpdateProgress()
Public Sub BaseClass_UpdateProgress() Handles Me.UpdateProgress
Progress += 1
End Sub
End Class

Public Class DerivedClass
Inherits BaseClass
Public Sub Test()
'do something
System.Threading.Thread.Sleep(2000)
RaiseEvent UpdateProgress()
End Sub
End Class

Public Class Form1
Public Sub Button1_Click(byval sender as object, byval e as System.EventArgs) Handles Button1.Click
Dim dc as New DerivedClass
dc.Test()
End Sub
End Class

Would it be better to use a method to update BaseClasses progress property from derived classes instead of an event?

Thanks for the help.

EDIT: Would it be even better to just increment the progress variable from within the derived classes code?

Viewing all articles
Browse latest Browse all 27154

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>