By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,041 Members | 1,018 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,041 IT Pros & Developers. It's quick & easy.

Error converting from C# to VB.Net

P: 2
Firstly, excuse me for my bad english.

Now to the point.

I converted a lot of code, and I had some errors in the conversion. There is one that I can't seem to figure it out:

Expand|Select|Wrap|Line Numbers
  1. Private Function MakeAnimation(ByVal [to] As Double, ByVal duration As Double, ByVal endEvent As EventHandler) As DoubleAnimation
  2.             Dim anim As New DoubleAnimation([to], TimeSpan.FromMilliseconds(duration))
  3.             anim.AccelerationRatio = 0.2
  4.             anim.DecelerationRatio = 0.7
  5.             If endEvent IsNot Nothing Then
  6.                 anim.Completed += endEvent
  7.             End If
  8.             Return anim
  9.         End Function
The line marked in bold (above) is where this error (shown below) comes up

Error 1 'Public Event Completed(sender As Object, e As System.EventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

I've tried to use this
Expand|Select|Wrap|Line Numbers
  1. AddHandler anim.Completed, AddressOf endEvent
But obviously, I don't have a method called "endEvent".

This code works perfectly in C#, but I don't know how to figure it out in VB.Net



Edit:

Some time ago, this issue was discussed, but the solution code wasn't shown
Apr 10 '12 #1

✓ answered by Monomachus

The short answer is use Handles. Although I'm not a VB programmer, I might be wrong :)

http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx

Also you could try this.

Expand|Select|Wrap|Line Numbers
  1. AddHandler anim.Completed, endEvent
  2.  
http://msdn.microsoft.com/en-us/libr...ks95.aspx#Y200

Share this Question
Share on Google+
2 Replies


Monomachus
Expert 100+
P: 127
The short answer is use Handles. Although I'm not a VB programmer, I might be wrong :)

http://msdn.microsoft.com/en-us/libr...(v=vs.71).aspx

Also you could try this.

Expand|Select|Wrap|Line Numbers
  1. AddHandler anim.Completed, endEvent
  2.  
http://msdn.microsoft.com/en-us/libr...ks95.aspx#Y200
Apr 10 '12 #2

P: 2
Very thanks for the answer!

It works perfectly!
Apr 10 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.