我打开了同一表单的多个实例,我想选择该表单的一个实例来集中注意力。所以我创建了一个组合框,其中列出了具有不同名称的该表单的所有标题,因此当我从组合框中选择一个标题它应该集中并且在前面。
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
If Application.OpenForms().OfType(Of Customers).Any Then
MessageBox.Show("Opened")
'code to select the form from the .text
'->
End If
End Sub
答案 0 :(得分:0)
创建List(Of Form)
可能更容易,当您使用表单名称填充ComboBox时,可以将每个表单添加到列表中。然后当你单击ComboBox中的第0项时,表单列表中索引0处的表单可能会被聚焦 - 这可能是这样吗?
'put this in your main declarations
Dim ListOfForms As New List(Of Form)
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
ListOfForms(ComboBox1.SelectedIndex).Focus()
End Sub
Private Sub PopulateComboBox()
ComboBox1.Items.Clear()
ListOfForms.Clear()
ComboBox1.Items.Add(frm1.Name)
ListOfForms.Add(frm1)
ComboBox1.Items.Add(frm2.Name)
ListOfForms.Add(frm2)
ComboBox1.Items.Add(frmX.Name)
ListOfForms.Add(frmX)
End Sub