我有 9 个标签,每个标签包含一个来自名为txthidden
. 当我点击一个按钮button3
时,标签会显示不同的字母数组。我的问题不是让它们出现,而是当文本框中没有 9 个字母时,它会出现错误消息:
Index was outside the bounds of the array.
有没有办法只显示与文本框长度匹配的标签?
提前致谢!
这是我的代码:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim hiddenarray() As Char
hiddenarray = Me.txthidden.Text.ToCharArray
lbl1.Text = hiddenarray(0)
lbl2.Text = hiddenarray(1)
lbl3.Text = hiddenarray(2)
lbl4.Text = hiddenarray(3)
lbl5.Text = hiddenarray(4)
lbl6.Text = hiddenarray(5)
lbl7.Text = hiddenarray(6)
lbl8.Text = hiddenarray(7)
lbl9.Text = hiddenarray(8)
End Sub