RaiseEvent in vb.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anandamd
    New Member
    • Dec 2008
    • 2

    #1

    RaiseEvent in vb.net

    Hi,
    I am a newbie to vb.net, I have converted C# code to vb.net using the online converter tools. I have got rid of all the error messages but there is one I can't seem to figure out. Any ideas or help is appreciated.

    Code:
    Private Function MakeAnimation(ByVal [to] As Double, ByVal duration As Double, ByVal endEvent As EventHandler) As DoubleAnimation
                Dim anim As New DoubleAnimation([to], TimeSpan.FromMilliseconds(duration))
                anim.AccelerationRatio = 0.2
                anim.DecelerationRatio = 0.7
                If endEvent IsNot Nothing Then
                    [B]anim.Completed += endEvent[/B]
                End If
                Return anim
            End Function
    The line marked in bold (above) is where this error (shown below) comes up

    Error 1 'Public Event Completed(sende r As Object, e As System.EventArg s)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event. C:\Documents and Settings\Tempor ary Projects\FishEy ePanel.vb 292 17


    Many Thanks
    @nand
  • zip929
    New Member
    • Dec 2008
    • 1

    #2
    Try using:
    AddHandler anim.Completed , Addressof endEvent

    endEvent will need to have the same signature as the anim.Completed Event
    i.e. (sender As Object, e As System.EventArg s)'

    Dave

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      You cannot directly assign an event handler like you are currently doing so.

      You need to use the AddHandler statement to dynamically assign an event handler.

      Comment

      • anandamd
        New Member
        • Dec 2008
        • 2

        #4
        Hi Zip929 and Frinavale,
        You guys rock. Thank you for the very quick pointers. Answer accepted. Please close this post.

        Many Thanks
        @nand

        Comment

        • ofek
          New Member
          • Apr 2007
          • 4

          #5
          Hi,
          If that's where the error is, I would simply put there:
          anim.Completed = anim.Completed + endEvent
          It might just work...

          Best regards,
          Ofek Cohany
          <link removed>
          Last edited by Frinavale; Dec 15 '08, 02:14 PM. Reason: removed link

          Comment

          Working...