我正在尝试制作一个具有更多开放式选项的搜索功能,在我为两个选项实现它之前,我想让它适用于一个,这是可以理解的。
我决定做的是制作一个自定义对话框,并用它来显示输入搜索条件产生的列表。
以下是调用对话框的代码:
Sub search(ByVal sender As Object, ByVal e As EventArgs) Handles btnSearch.Click
Dim temp As String
Dim tempSplit As String()
Dim check As Boolean = False
'instance creation of dialog box
Dim extendSearch As New TypeClassSearch()
Select Case cmbSearch.Text
Case "Name"
'working and appropiate code
Exit Select
Case "Number"
'working and appropriate code
Exit Select
Case "Type"
check = True
'shows dialog
extendSearch.Show()
'doesn't wait for input from the dialog and just goes through the code before user can interact
If extendSearch.DialogResult() = System.Windows.Forms.DialogResult.OK Then
For i As Integer = 0 To pokemonList.Length - 1
If extendSearch.selection = pokemonList(i) Then
temp = weaknesses(i)
tempSplit = temp.Split(CChar("\"))
weaknesses(i) = ""
For k As Integer = 0 To tempSplit.Length - 1
If k <> tempSplit.Length - 1 Then
weaknesses(i) += tempSplit(k) + ", "
Else
weaknesses(i) += tempSplit(k)
End If
Next
temp = resist(i)
tempSplit = temp.Split(CChar("\"))
resist(i) = ""
For k As Integer = 0 To tempSplit.Length - 1
If k <> tempSplit.Length - 1 Then
resist(i) += tempSplit(k) + ", "
Else
resist(i) += tempSplit(k)
End If
Next
lblNum.Text = pokedexNum(i)
lblPkmn.Text = pokemonList(i)
lblType.Text = typings(i)
lblClass.Text = classifications(i)
lblWeak.Text = weaknesses(i)
lblResist.Text = resist(i)
lblPkdxX.Text = pokedexX(i)
lblPkdxY.Text = pokedexY(i)
End If
Next
End If
Exit Select
Case "Class"
'hold code, next extended criteria
Exit Select
End Select
If check = False Then
MessageBox.Show("Pokemon Not Found. Please check your spelling or try again.")
End If
End Sub
我的对话框是一段简单的代码:
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.OK
selection = CStr(chkSearch.SelectedItem)
Me.Close()
End Sub
非常感谢任何帮助。 =)
答案 0 :(得分:2)
将extendSearch.Show()
更改为extendSearch.ShowDialog()