【发布时间】:2014-07-15 10:03:34
【问题描述】:
此代码在 Keypress 事件中
当我尝试输入 -1、-2 或 1.1 -1.3 时没有问题,但是当我尝试在文本框中输入 1/2 和 1/4 时,我只在这个“1/”上存货。 我认为我的代码有问题,但根本没有错误消息,我无法弄清楚。 . 任何形式的帮助和建议都非常感谢。 .
Dim tb As TextBox = CType(sender, TextBox)
Dim chr As Char = e.KeyChar
If IsNumeric(e.KeyChar) And Not e.KeyChar = "-" Then
e.Handled = Not IsNumeric(tb.Text & e.KeyChar)
ElseIf IsNumeric(e.KeyChar) And Not e.KeyChar = "/" Then
e.Handled = Not IsNumeric(tb.Text & e.KeyChar)
ElseIf e.KeyChar = "." Then
If Not (tb.SelectedText = "." Or IsNumeric(tb.Text & e.KeyChar)) Then
e.Handled = True
End If
ElseIf e.KeyChar = "/" Then
If tb.SelectionStart <> 1 Or Microsoft.VisualBasic.Left(tb.Text, 1) = "/" Then
e.Handled = True
End If
ElseIf e.KeyChar = "-" Then
If tb.SelectionStart <> 0 Or Microsoft.VisualBasic.Left(tb.Text, 1) = "-" Then
e.Handled = True
End If
ElseIf Not Char.IsControl(e.KeyChar) Then
e.Handled = True
End If
【问题讨论】:
-
“仅存货” 1/ 是什么意思?
-
@rontornambe 我认为 OP 的意思是,“他只停留在 1/”,只是我的猜测......
-
我想像这样输入:“1/2”,但是当我这样做时,这个“1/”上的库存我不能再添加任何数字了。
-
"1/2" 不是数字。顺便说一句,这个词是“卡住”。强烈建议使用调试器单步调试此类代码。
标签: vb.net vb.net-2010