简体   繁体   English

将焦点放在数组中的文本框上

[英]Set focus on text box that is in array

I'm trying to validate my inputs. 我正在尝试验证我的输入。 Each text box input is put into an array strExamAnswer(). 每个文本框输入都放入数组strExamAnswer()。 As my user inputs A, B, C, or DI need to validate they are entering acceptable inputs. 当我的用户输入A,B,C或DI需要验证他们输入的是可接受的输入时。 I have the validation correct but I want the incorrect text box to gain focus after validation catches the incorrect input. 我的验证正确,但我希望验证捕获到错误的输入后,不正确的文本框才能获得焦点。 How can I get the focus on the said text box using a loop that is checking each input in the array? 如何使用检查数组中每个输入的循环将焦点放在所述文本框中?

Private Sub Validatation(ByVal intIndex As Integer)
    Dim strA As String = "A"
    Dim strB As String = "B"
    Dim strC As String = "C"
    Dim strD As String = "D"


    For i = 0 To 19
        If strExamAnswer(i) = strA Then
            blnOk = True
        ElseIf strExamAnswer(i) = strB Then
            blnOk = True
        ElseIf strExamAnswer(i) = strC Then
            blnOk = True
        ElseIf strExamAnswer(i) = strD Then
            blnOk = True
        Else
            MessageBox.Show("Please enter A, B, C, D for Answer " & strQuestion(i))
            blnOk = False
            Exit Sub
        End If
    Next

    blnOk = True

End Sub

So when this code kicks one of the questions back how do I tell it to focus on that specific text box in the array it is kicking out as invalid? 因此,当此代码引发问题之一时,我如何告诉它将焦点放在数组中的特定文本框中呢? Is there even a way to do this in a loop using an array. 有没有办法在使用数组的循环中做到这一点。 I would rather keep in a loop to limit amount of code. 我宁愿保持循环以限制代码量。 I could set up in a Case I just rather not. 我可以设置一个案例,但我不愿意这样做。

假设该数组名为txtInput,并且具有与strExamAnswer相同的尺寸。

txtInput(i).Focus()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM