每次一个事件

时间:2018-11-16 16:47:07

标签: xaml

每次点击一次该怎么做

2 个答案:

答案 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