有一个名为TxtNum的TextBox文本框,要求只能输入有效实数,代码如下:
Private Sub TxtNum_KeyPress(ByVal sender As System.Object,ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtNum.KeyPress Dim b As Boolean = True If Char.IsDigit(e.KeyChar) Or e.KeyChar = Chr(8) Then e.Handled = False ElseIf e.KeyChar = Chr(46) And Not TxtNum.Text.Equals("") And b Then e.Handled = False b = False Else e.Handled = True End If End Sub