...is an event and cannot be called directly. Use a RaiseEvent statement to raise an event

Hi Experts,

I am converting an application that was programmed in C# into VB.  I've got it all translated except for the last form.
There is one line giving me grief.  The two errors that I get relating to the "inmemoryMarkerOverlay.Click += ..." line are:

Public Event Click(sender As Object, e As ThinkGeo.MapSuite.WebEdition.MarkerOverlayClickEventArgs) is an event and cannot be called
directly. Use a RaiseEvent to raise an event.

Delegate 'System.EventHandler(Of ThinkGeo.MapSuite.WebEdition.MarkerOverlayClickEventArgs) requires an 'AddressOf' expression or lambda
expression as the only argument to its constructor.

How can I convert the line below so that it raises the event when the users click event fires?

Thx in advance!

Private Function InitializeMarkerOverlays(ByVal vehicles As Dictionary(Of String, Vehicle)) As Dictionary(Of String, InMemoryMarkerOverlay)
        Dim markerOverlays As New Dictionary(Of String, InMemoryMarkerOverlay)()

        For Each item As KeyValuePair(Of String, Vehicle) In vehicles

            Dim inmemoryMarkerOverlay As New InMemoryMarkerOverlay()
            inmemoryMarkerOverlay.IsBaseOverlay = False

            inmemoryMarkerOverlay.Click += New EventHandler(Of MarkerOverlayClickEventArgs)(InMemoryMarkerOverlay_Click)

            inmemoryMarkerOverlay.ZoomLevelSet.ZoomLevel01.CustomMarkerStyle = GetCustomMarkerStyle(item.Value.IconPath, item.Value.VehicleName, item.Value.Direction, item.Value)
            inmemoryMarkerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20

            markerOverlays.Add(item.Key, inmemoryMarkerOverlay)

        Return markerOverlays
    End Function

    Private Sub InMemoryMarkerOverlay_Click(ByVal sender As Object, ByVal args As MarkerOverlayClickEventArgs)

        Dim clickedVehicle As Vehicle = (DirectCast(Session("TrackingVehicles"), Dictionary(Of String, Vehicle)))(args.FeatureId)

        Map1.Popups.Add(GetPopup(GetPopupHtmlTemplate(clickedVehicle), clickedVehicle))
    End Sub

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

That's C#'s way of adding an event handler. VB.Net uses the Addhandler statement. Replace that line with this:

Addhandler inmemoryMarkerOverlay.Click, AddressOf InMemoryMarkerOverlay_Click
For clarity sake, this line:
inmemoryMarkerOverlay.Click += New EventHandler(Of MarkerOverlayClickEventArgs)(InMemoryMarkerOverlay_Click)

should be replaced by:
Addhandler inmemoryMarkerOverlay.Click, AddressOf InMemoryMarkerOverlay_Click

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sharizodAuthor Commented:
Thanks HawkValley1, but how do I specify the handler is of type MarkerOverlayClickEventArgs in VB as I do in C# ?
If it does not recognize the MarkerOverlayClickEventArgs, you may have to full qualify it with ThinkGeo.MapSuite.WebEdition.MarkerOverlayClickEventArgs in the signature of the event.
Or - Imports ThinkGeo.MapSuite.WebEdition .
sharizodAuthor Commented:
Thanks very much Hawkvalley1!  That fit the bill quite nicely!  Sorry for the delay in finalizing things!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.