VB.NET TextBox 只允许输入1-100之间的整数 简洁篇

     Dim Str As String = ""
Private Sub txtRecond_KeyUp(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles txtRecond.KeyUp
txtRecond.Text = Regex.Replace(txtRecond.Text, "[^0-9]", "")
If txtRecond.Text = "" Then
Return
End If
Try
Dim num As Integer = Integer.Parse(txtRecond.Text)
txtRecond.Text = num.ToString()
If (num > ) Or (num = ) Then
txtRecond.Text = ""
End If
Catch ex As Exception
txtRecond.Text = ""
End Try End Sub Private Sub txtRecond_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtRecond.KeyPress
If Char.IsDigit(e.KeyChar) Or e.KeyChar = Chr() Or e.KeyChar = "." Then
If e.KeyChar = "." And InStr(txtRecond.Text, ".") > Then
e.Handled = True
Else
e.Handled = False
End If
Else
e.Handled = True
End If End Sub
上一篇:windows系统修改mysql端口的方法


下一篇:LeetCode:Multiply Strings