首页 > Web开发 > 详细

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

时间:2014-01-24 17:18:01      阅读:443      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 1     Dim Str As String = ""
 2     Private Sub txtRecond_KeyUp(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles txtRecond.KeyUp
 3         txtRecond.Text = Regex.Replace(txtRecond.Text, "[^0-9]", "")
 4         If txtRecond.Text = "" Then
 5             Return
 6         End If
 7         Try
 8             Dim num As Integer = Integer.Parse(txtRecond.Text)
 9             txtRecond.Text = num.ToString()
10             If (num > 100) Or (num = 0) Then
11                 txtRecond.Text = ""
12             End If
13         Catch ex As Exception
14             txtRecond.Text = ""
15         End Try
16 
17 
18     End Sub
19 
20     Private Sub txtRecond_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtRecond.KeyPress
21         If Char.IsDigit(e.KeyChar) Or e.KeyChar = Chr(8) Or e.KeyChar = "." Then
22             If e.KeyChar = "." And InStr(txtRecond.Text, ".") > 0 Then
23                 e.Handled = True
24             Else
25                 e.Handled = False
26             End If
27         Else
28             e.Handled = True
29         End If
30 
31     End Sub
View Code

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

原文:http://www.cnblogs.com/wuhuisheng/p/3531978.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!