什么是用于连接和声明事件的C#代码的VB.NET等价物?
我正在开发一个在Silverlight中构建媒体播放器的教程 ,我正在尝试将EventHandler
到DispatchTimer
对象的timer.Tick
事件,以便video的时间与Slider
对象同步。
示例代码在C#中,我不能在我的生活中找出VB.NET中使用RaiseEvent
和/或Handles
连接事件的正确语法。 以下是相关的C#代码。 我会在我遇到困境的地方加上评论。
private DispatchTimer timer; public Page() { //... timer = new DispatchTimer(); timer.Interval = TimeSpan.FromMilliseconds(50); timer.Tick += new EventHandler(timer_Tick); // 0) { sliderScrubber.Value = VideoElement.Position.TotalSeconds / VideoElement.NaturalDuration.TimeSpan.TotalSeconds; } }
像这样:
AddHandler timer.Tick, AddressOf timer_Tick
或者,
Private WithEvents timer as DispatcherTimer Sub timer_Tick(sender As Object, e As EventArgs) Handles timer.Tick End Sub