如果有人通过写入100
将特定字词输入txtUsername
,我可以使进度条等于Dim word1 As String = "14TSmith"
If txtUsername = word1 Then
progressbar1.value = 100
End If
。
2-20
(抱歉,我无法复制并粘贴确切的代码,因为它在另一个系统上)
但我希望用户输入长度为{{1}}个字符的任何字符串,而不仅仅是特定字词。
答案 0 :(得分:3)
If txtusername.TextLength >= 2 And txtusername.TextLength <= 20 Then
ProgressBar1.Value = 100
End If
我希望这会有所帮助。
答案 1 :(得分:1)
如果您想根据长度向用户提供密码“好”的反馈,那么:
Public Class Form1
Private Const MinLength As Integer = 2
Private Const MaxLength As Integer = 20
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TextBox1.MaxLength = MaxLength
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Dim Percent As Double
If TextBox1.TextLength < MinLength Then
Percent = 0
Else
Percent = CDbl(TextBox1.TextLength) / CDbl(MaxLength)
End If
Dim value As Integer = ProgressBar1.Minimum + (ProgressBar1.Maximum - ProgressBar1.Minimum) * Percent
ProgressBar1.Value = Math.Max(Math.Min(value, ProgressBar1.Maximum), ProgressBar1.Minimum)
End Sub
End Class