Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the VB.NET equivalent of this C# code for wiring up and declaring an event?

I'm working on a tutorial to build a media player in Silverlight and am trying to wire up an EventHandler to the timer.Tick event of a DispatchTimer object so that the time of the video is synced with a Slider object.

The sample code is in C# and I can't for the life of me figure out the proper syntax in VB.NET with RaiseEvent and/or Handles to wire up the event. Below is the relevant C# code. I'll include comments on where I'm getting stuck.

private DispatchTimer timer;

public Page()
{
    //...
    timer = new DispatchTimer();
    timer.Interval = TimeSpan.FromMilliseconds(50);
    timer.Tick += new EventHandler(timer_Tick); // <== I get stuck here b/c
        // I can't do "timer.Tick += ..." in VB.NET
}

void timer_Tick(object sender, EventArgs e)
{
     if (VideoElement.NaturalDuration.TimeSpan.TotalSeconds > 0)
     {
         sliderScrubber.Value = VideoElement.Position.TotalSeconds /
             VideoElement.NaturalDuration.TimeSpan.TotalSeconds;
     }
}
like image 429
Ben McCormack Avatar asked May 26 '10 01:05

Ben McCormack


People also ask

Is VB.NET C based?

It is pronounced as Visual Basic . NET, which is an updated feature and version of Classic Visual Basic 6.0. It is pronounced as "C SHARP" language, that belongs to the C family.

Is VB.NET similar to C++?

The main difference between Visual Basic and Visual C++ is that Visual Basic is an Object Oriented Programming Language while Visual C++ is an Integrated Development Environment (IDE). Visual Basic is a user-friendly programming language developed by Microsoft.

What language is VB.NET similar to?

With VB.NET, you can create applications that are fully object-oriented, similar to the ones created in other languages like C++, Java, or C#.

Does VB.NET use C#?

Though C# and VB.NET are syntactically very different, that is where the differences mostly end. Microsoft developed both of these languages to be part of the same . NET Framework development platform. They are both developed, managed, and supported by the same language development team at Microsoft.


1 Answers

Like this:

AddHandler timer.Tick, AddressOf timer_Tick

Alternatively,

Private WithEvents timer as DispatcherTimer


Sub timer_Tick(sender As Object, e As EventArgs) Handles timer.Tick

End Sub
like image 142
SLaks Avatar answered Oct 23 '22 11:10

SLaks