【发布时间】:2014-08-15 05:18:28
【问题描述】:
我正在尝试在 VB.Net 中编写迪斯科灯光机。 我在 WPF 上有四个椭圆,我希望它们“点亮”(=将填充从白色更改为某种颜色),然后 等待 0.5 秒,然后将填充改回白色 -一切都按照预先写好的顺序。
我正在尝试使用 DispatherTimer,但我实际上并不知道如何使它工作。 省略号是名称 pad0、pad1 等...
Public Sub timer()
Dim t As New System.Windows.Threading.DispatcherTimer()
AddHandler t.Tick, AddressOf dispatcherTimer_Tick
t.Interval = New TimeSpan(0, 0, 1)
End Sub
Private Sub dispatcherTimer_Tick(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Private Sub play_Click(sender As Object, e As RoutedEventArgs) Handles play.Click
Dim sequence = New Integer() {1, 0, 3, 2}
For i As Integer = 0 To 3
Select Case sequence(i)
Case 0
pad0.Fill = Brushes.Blue
**this is where I want the timer to run!**
padOff(pad0)
Case 1
pad1.Fill = Brushes.Yellow
**this is where I want the timer to run!**
padOff(pad1)
Case 2
pad2.Fill = Brushes.Green
**this is where I want the timer to run!**
padOff(pad2)
Case 3
pad3.Fill = Brushes.Red
**this is where I want the timer to run!**
padOff(pad3)
End Select
Next
End Sub
Public Sub padOff(ByVal pad As Shape)
pad.Fill = Brushes.White
End Sub
【问题讨论】:
-
这是一个事件驱动的世界。没有油漆,没有派对
-
只是一个注释。
Brushes类中有很多预定义的画笔,例如Brushes.White。无需创建自己的。 -
@Clemens 谢谢,我已经更新了我的代码。
标签: wpf vb.net dispatchertimer