只允許文本框輸入數字,退格鍵,小數點,負號
VB.NET
Private Sub PermitInputNumber(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtTopRead0.KeyPress,txtTopRead120 ,txtTopRead240 ,txtTopRead360 ,txtBottomRead0 ,txtBottomRead120 ,txtBottomRead240 ,txtBottomRead360
If Not e.KeyChar = Chr(8) And Not Char.IsDigit(e.KeyChar) And Not e.KeyChar = "." And Not e.KeyChar = "-" Then
e.Handled = True
End If
End Sub
C#:
private void PermitInputNumber(System.Object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (!e.KeyChar == Strings.Chr(8) && !char.IsDigit(e.KeyChar) && !e.KeyChar == "." && !e.KeyChar == "-")
e.Handled = true;
}