由网友(赢得天下输了她)分享简介:我工作的一个教程建立一个媒体播放器Silverlight中,我试图连线了一个事件处理程序到 timer.Tick 事件一个 DispatchTimer 对象,使视频的时间同步与滑块对象。样品code是在C#中,我不能为我的生活搞清楚VB.NET正确的语法与的RaiseEvent 和/或手柄要连接的事件。下面是有关C#c...![vb.net 教程 3 10 窗体编程 datagridview控件 13 解决单元格按钮或超链接点击的问题](https://p.xsw88.cn/allimgs/daicuo/20230904/8369.png)
我工作的一个教程建立一个媒体播放器Silverlight中,我试图连线了一个事件处理程序
到 timer.Tick
事件一个 DispatchTimer
对象,使视频的时间同步与滑块
对象。
样品code是在C#中,我不能为我的生活搞清楚VB.NET正确的语法与的RaiseEvent
和/或手柄
要连接的事件。下面是有关C#code。我会包括在那里我被卡住的意见。
私人DispatchTimer定时器;
公共页面()
{
// ...
定时器=新DispatchTimer();
timer.Interval = TimeSpan.FromMilliseconds(50);
timer.Tick + =新的EventHandler(timer_Tick); //< ==我被困在这里B / C
//我不能这样做timer.Tick + = ......在VB.NET
}
无效timer_Tick(对象发件人,EventArgs的)
{
如果(VideoElement.NaturalDuration.TimeSpan.TotalSeconds大于0)
{
sliderScrubber.Value = VideoElement.Position.TotalSeconds /
VideoElement.NaturalDuration.TimeSpan.TotalSeconds;
}
}
解决方案
这样的:
的AddHandler timer.Tick,AddressOf timer_Tick
另外,
私有WithEvents就定时器作为DispatcherTimer
子timer_Tick(发送者为对象,E作为EventArgs的)把手timer.Tick
结束小组
![vb.net 教程 3 10 窗体编程 datagridview控件 13 解决单元格按钮或超链接点击的问题](https://p.xsw88.cn/allimgs/daicuo/20230904/8369.png)
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 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
相关推荐
最新文章