我实际上是vb中的新手并试图学习它,我有一个包含13个集合和一个按钮的组合框,我希望每当用户从组合框中选择一个选项并单击按钮时,它应该以单独的形式打开。但问题是每当用户点击一个选项时,所有13个表格都将打开。
请帮忙 这是我的代码
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ComboBox1.SelectedValue = "1"
Form2.Show()
Me.Hide()
ComboBox1.SelectedItem = "2"
Form3.Show()
Me.Hide()
ComboBox1.SelectedItem = "3"
Form4.Show()
ComboBox1.SelectedValue = "4"
Form3.Show()
Me.Hide()
ComboBox1.SelectedItem = "5"
Form5.Show()
Me.Hide()
ComboBox1.SelectedItem = "6"
Form6.Show()
ComboBox1.SelectedValue = "7"
Form7.Show()
Me.Hide()
ComboBox1.SelectedItem = "8"
Form8.Show()
Me.Hide()
ComboBox1.SelectedItem = "9"
Form9.Show()
ComboBox1.SelectedValue = "10"
Form9.Show()
Me.Hide()
ComboBox1.SelectedItem = "11"
Form10.Show()
Me.Hide()
ComboBox1.SelectedItem = "12"
Form11.Show()
Me.Hide()
ComboBox1.SelectedItem = "13"
Form12.Show()
Me.Hide()
End Sub
答案 0 :(得分:0)
根据您的目的, 而其他成员已经建议你的, 听起来你没有正确格式化if ... then和/或你的select ... case语句。
下面的代码应该做你想做的事情。 我们使用SELECTINDEX属性来确定当前选择下拉列表中的哪个索引元素。
此外,如果您有任何设置,则下面的代码可能会受到组合框/下拉对象的事件过程中的任何代码的影响(受影响,因此无效)。
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'
Select Case Combobox1.SelectedIndex
Case 1
Form2.Show()
Me.Hide()
Case 1, 4
Form3.Show()
Me.Hide()
Case 3
Form4.Show()
Me.Hide()
Case 5
Form5.Show()
Me.Hide()
Case 6
Form6.Show()
Me.Hide()
Case 7
Form7.Show()
Me.Hide()
Case 8
Form8.Show()
Me.Hide()
Case 9, 10
Form9.Show()
Me.Hide()
Case 11
Form10.Show()
Me.Hide()
Case 12
Form11.Show()
Me.Hide()
Case 13
Form12.Show()
Me.Hide()
End Select
'
End Sub