Visual Basic表单,通过变量

时间:2017-10-20 02:55:41

标签: vb.net

好的我的问题是我无法找到如何解决的问题,因为这是一个问题我认为没有多少人会有,但我的代码(下面)

在按钮1上单击和for循环我希望更改代码中的listbox1,以便在代码运行一次时更改为listbox2。我希望我已经正确解释了我会感激任何帮助改进,因为我刚开始使用vb。

Public Class FrmMain
Dim g1, g2, g3, g4, g5, g6, g7, g8, g9, g10, g11, g12, g13, g14, g15, g16, g17, g18, g19, g20, g21, g22, g23, g24, g25 As Integer
Private Sub ListBox1_click(sender As Object, e As EventArgs) Handles ListBox1.Click
    ListBox1.BackColor = Color.LawnGreen
    g1 = 1
End Sub

Private Sub ListBox25_click(sender As Object, e As EventArgs) Handles ListBox25.Click
    ListBox25.BackColor = Color.LawnGreen
    g25 = 1
End Sub

Private Sub ListBox24_click(sender As Object, e As EventArgs) Handles ListBox24.Click
    ListBox24.BackColor = Color.LawnGreen
    g24 = 1
End Sub

Private Sub ListBox23_click(sender As Object, e As EventArgs) Handles ListBox23.Click
    ListBox23.BackColor = Color.LawnGreen
    g23 = 1
End Sub

Private Sub ListBox22_click(sender As Object, e As EventArgs) Handles ListBox22.Click
    ListBox22.BackColor = Color.LawnGreen
    g22 = 1
End Sub

Private Sub ListBox21_click(sender As Object, e As EventArgs) Handles ListBox21.Click
    ListBox21.BackColor = Color.LawnGreen
    g21 = 1
End Sub

Private Sub ListBox20_click(sender As Object, e As EventArgs) Handles ListBox20.Click
    ListBox20.BackColor = Color.LawnGreen
    g20 = 1
End Sub

Private Sub ListBox19_click(sender As Object, e As EventArgs) Handles ListBox19.Click
    ListBox19.BackColor = Color.LawnGreen
    g19 = 1
End Sub

Private Sub ListBox18_click(sender As Object, e As EventArgs) Handles ListBox18.Click
    ListBox18.BackColor = Color.LawnGreen
    g18 = 1
End Sub

Private Sub ListBox17_click(sender As Object, e As EventArgs) Handles ListBox17.Click
    g17 = 1
    ListBox17.BackColor = Color.LawnGreen
End Sub

Private Sub ListBox16_click(sender As Object, e As EventArgs) Handles ListBox16.Click
    ListBox16.BackColor = Color.LawnGreen
    g16 = 1
End Sub

Private Sub ListBox15_click(sender As Object, e As EventArgs) Handles ListBox15.Click
    ListBox15.BackColor = Color.LawnGreen
    g15 = 1
End Sub

Private Sub ListBox14_click(sender As Object, e As EventArgs) Handles ListBox14.Click
    ListBox14.BackColor = Color.LawnGreen
    g14 = 1
End Sub

Private Sub ListBox13_click(sender As Object, e As EventArgs) Handles ListBox13.Click
    ListBox13.BackColor = Color.LawnGreen
    g13 = 1
End Sub

Private Sub ListBox12_click(sender As Object, e As EventArgs) Handles ListBox12.Click
    ListBox12.BackColor = Color.LawnGreen
    g12 = 1
End Sub

Private Sub ListBox11_click(sender As Object, e As EventArgs) Handles ListBox11.Click
    g11 = 1
    ListBox11.BackColor = Color.LawnGreen
End Sub

Private Sub ListBox10_click(sender As Object, e As EventArgs) Handles ListBox10.Click
    g10 = 1
    ListBox10.BackColor = Color.LawnGreen
End Sub

Private Sub ListBox9_click(sender As Object, e As EventArgs) Handles ListBox9.Click
    ListBox9.BackColor = Color.LawnGreen
    g9 = 1
End Sub

Private Sub ListBox8_click(sender As Object, e As EventArgs) Handles ListBox8.Click
    ListBox8.BackColor = Color.LawnGreen
    g8 = 1
End Sub

Private Sub ListBox7_click(sender As Object, e As EventArgs) Handles ListBox7.Click
    ListBox7.BackColor = Color.LawnGreen
    g7 = 1
End Sub

Private Sub ListBox6_click(sender As Object, e As EventArgs) Handles ListBox6.Click
    ListBox6.BackColor = Color.LawnGreen
    g6 = 1
End Sub

Private Sub ListBox5_click(sender As Object, e As EventArgs) Handles ListBox5.Click
    ListBox5.BackColor = Color.LawnGreen
    g5 = 1
End Sub

Private Sub ListBox4_click(sender As Object, e As EventArgs) Handles ListBox4.Click
    ListBox4.BackColor = Color.LawnGreen
    g4 = 1
End Sub

Private Sub ListBox3_click(sender As Object, e As EventArgs) Handles ListBox3.Click
    ListBox3.BackColor = Color.LawnGreen
    g3 = 1
End Sub

Private Sub ListBox2_click(sender As Object, e As EventArgs) Handles ListBox2.Click
    ListBox2.BackColor = Color.LawnGreen
    g2 = 1
End Sub

Private Sub Btn_Generate_Click(sender As Object, e As EventArgs) Handles Btn_Generate.Click
    Dim List1 As New List(Of String)
    Dim test As Integer
    Dim lb As String
    List1.Add("test1")
    List1.Add("test2")
    List1.Add("test3")
    List1.Add("test4")
    List1.Add("test5")
    List1.Add("test6")
    List1.Add("test7")
    List1.Add("test8")
    List1.Add("test9")
    List1.Add("test10")
    List1.Add("test11")
    List1.Add("test12")
    List1.Add("test13")
    List1.Add("test14")
    List1.Add("test15")
    List1.Add("test16")
    List1.Add("test17")
    List1.Add("test18")
    List1.Add("test19")
    List1.Add("test20")
    List1.Add("test21")
    List1.Add("test22")
    List1.Add("test23")
    List1.Add("test24")
    List1.Add("test25")
    List1.Add("test26")
    List1.Add("test27")
    List1.Add("test28")
    List1.Add("test29")
    List1.Add("test30")
    List1.Add("test31")
    List1.Add("test32")
    List1.Add("test33")
    List1.Add("test34")
    List1.Add("test35")
    List1.Add("test36")
    List1.Add("test37")
    List1.Add("test38")
    List1.Add("test39")
    List1.Add("test40")
    For i = 1 To List1.Count
        Randomize()
        test = Rnd(List1.Count)

        If List1.Count > 1 Then

            ListBox1.Items.Add(List1.Item(test))
            List1.Remove(List1.Item(test))
        End If

    Next
    ListBox1.BackColor = Color.White
    ListBox2.BackColor = Color.White
    ListBox3.BackColor = Color.White
    ListBox4.BackColor = Color.White
    ListBox5.BackColor = Color.White
    ListBox6.BackColor = Color.White
    ListBox7.BackColor = Color.White
    ListBox8.BackColor = Color.White
    ListBox9.BackColor = Color.White
    ListBox10.BackColor = Color.White
    ListBox11.BackColor = Color.White
    ListBox12.BackColor = Color.White
    ListBox13.BackColor = Color.White
    ListBox14.BackColor = Color.White
    ListBox15.BackColor = Color.White
    ListBox16.BackColor = Color.White
    ListBox17.BackColor = Color.White
    ListBox18.BackColor = Color.White
    ListBox19.BackColor = Color.White
    ListBox20.BackColor = Color.White
    ListBox21.BackColor = Color.White
    ListBox22.BackColor = Color.White
    ListBox23.BackColor = Color.White
    ListBox24.BackColor = Color.White
    ListBox25.BackColor = Color.White

End Sub

结束班

0 个答案:

没有答案