每次点击一次该怎么做
答案 0 :(得分:1)
我有一些可以尝试的东西。我没有使用IsNullOrEmpty
测试,因为您已经预先重置了它们,所以不需要。
将Buttons
放在一个小的数组中可以简化操作。
您可以尝试以下方法:(已通过Option Strict On
测试)
Private Sub ButtonShuffle_Click(sender As Object, e As RoutedEventArgs) Handles ButtonShuffle.Click
Dim rnd As New Random
Dim numberList As List(Of Integer) = Enumerable.Range(0, 10).OrderBy(Function(i) rnd.Next).ToList
Dim buttons As Button() = {Button0, Button1, Button2, Button3, Button4, Button5, Button6, Button7, Button8, Button9}
Dim buttonCurrent As Integer = 0
For Each num As Integer In numberList
buttons(buttonCurrent).Content = num.ToString
buttonCurrent += 1
Next
End Sub
答案 1 :(得分:0)
将您所有的Button0
删除为Button9
Click
个事件,并将其替换为:
Private Sub Buttons_Click(sender As Object, e As RoutedEventArgs) Handles Button0.Click, Button1.Click, Button2.Click, Button3.Click, Button4.Click, Button5.Click, Button6.Click, Button7.Click, Button8.Click, Button9.Click
Shuffle()
End Sub