Larry Howard Mittman Larry Howard Mittman - 3 months ago 12x Question

How to raise Windows.Forms.WebBrowserDocumentCompletedEventHandler event in derived class

I am converting a C# program to VB,Net. The conversion created the following line:

Me.axWebBrowser1.DocumentCompleted += New Windows.Forms.WebBrowserDocumentCompletedEventHandler(AddressOf Me.axWebBrowser1_DocumentComplete)

This line creates the following error message:

Error 17 'Public Event DocumentCompleted(sender As Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

I can not find whether there is a RaiseEvent statement in the Systems class which I can use to raise the event. I can not do it in my derived class.


You're not trying to raise the event, you're trying to subscribe to it.

In VB.NET this is done using an AddHandler statement:

AddHandler Me.axWebBrowser1.DocumentCompleted, AddressOf Me.axWebBrowser1_DocumentComplete

Also a statement isn't located inside a class, namespace or library. A statement is a line, or multiple lines, of code that goes together. So, not related to your problem, but you can read about the RaiseEvent statement.