Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15429

VS 2019 [RESOLVED] Raising an event when the object is instantiated

$
0
0
Hello friends :wave:

I'm trying to fire up an event when my object is instantiated right after the form show's event, but it's not working.

Here is what I did:

Code:

Public Class MyObject

    Public Event FileNotFoundEvent(message As String)

    Public Sub New()

        If Not System.IO.File.Exists("bla") Then
            RaiseEvent FileNotFoundEvent("File not found.")
        End If

    End Sub

End Class

My form's code..

Code:


    Private WithEvents TestClass As MyObject

    Public Sub OnFileNotFoundEvent(message As String) Handles TestClass.FileNotFoundEvent
        MessageBox.Show(message)
    End Sub

    Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
        TestClass = New MyObject()
    End Sub

What am I doing wrong?

Viewing all articles
Browse latest Browse all 15429

Latest Images

Trending Articles



Latest Images

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