I'm trying to write some code which will raise an event in one of my objects which is then handled in one of my window forms. It appears to be quite simple but I can't get the code to work; the program creates the person object, sets the person's name, and even raises the event but doesn't handle the event in the form code. I've copied the class code which contained the 'event' and 'raiseevent' into the main program and it still doesn't work. I'm not sure what the problem is but any help would be appreciate.
The code is written in VB.NET using the VS Express 2012 IDE software.
Public Class clsPerson
Private m_name As String
Public Event personviewed()
Public Property name() As String
Get
name = m_name
End Get
Set(value As String)
m_name = value
End Set
End Property
Public Sub personviewedmethod()
RaiseEvent personviewed()
End Sub
End Class
and
Public Class Form1
Public WithEvents clsperson1 As clsPerson
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim clsperson1 As New clsPerson
clsperson1.name = "PersonsName"
clsperson1.personviewedmethod()
End Sub
Private Sub personviewed() Handles clsperson1.personviewed
MessageBox.Show("***Event raised**")
End Sub
End Class