Vb.net 文本输入框中只允许某些值
您是否认为该程序的用户只允许在文本输入框中输入某些数字? 例如: 14785(,00) 14787,50 14790(,00) 所以这个例子大约有2.5个步骤。还可以有其他步骤,例如1.5步骤。进一步的要求是1)德语符号(Vb.net 文本输入框中只允许某些值,vb.net,textbox,Vb.net,Textbox,您是否认为该程序的用户只允许在文本输入框中输入某些数字? 例如: 14785(,00) 14787,50 14790(,00) 所以这个例子大约有2.5个步骤。还可以有其他步骤,例如1.5步骤。进一步的要求是1)德语符号(,作为十进制分隔符)和2)只有正数。我已经有了。 由于这个网格,我不能使用数字上下控件,模不适合双精度 Public Class FormMain Private Entry As Double = 0R Private ReadOnly Deu As New
,
作为十进制分隔符)和2)只有正数。我已经有了。
由于这个网格,我不能使用数字上下控件
,模不适合双精度
Public Class FormMain
Private Entry As Double = 0R
Private ReadOnly Deu As New System.Globalization.CultureInfo("de-DE")
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Dim erfolgreich As Boolean = Double.TryParse(TextBox1.Text, System.Globalization.NumberStyles.Float, Deu, Entry)
If erfolgreich AndAlso Entry > 0.0 Then
TextBox1.ForeColor = Color.Green
Else
TextBox1.ForeColor = Color.Red
End If
End Sub
End Class
我解决了这个问题。我将输入的双精度值乘以10.0,然后将其转换为
Long
。然后,我使用模来检查被25L除法的余数是否为0L
Public Class FormMain
Private Entry As Double = 0R
Private ReadOnly Deu As New System.Globalization.CultureInfo("de-DE")
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Dim erfolgreich As Boolean = Double.TryParse(TextBox1.Text, System.Globalization.NumberStyles.Float, Deu, Entry)
If erfolgreich AndAlso Entry > 0.0 Then
Dim Eingabe_als_Long As Long = Convert.ToInt64(Entry * 10.0)
If Eingabe_als_Long Mod 25L = 0L Then
TextBox1.ForeColor = Color.Green
Else
TextBox1.ForeColor = Color.Red
End If
Else
TextBox1.ForeColor = Color.Red
End If
End Sub
End Class
Textbox控件具有Lines数组属性,因此可以使用OnChanged和/或Leaf属性触发检查Lines数组中每个项的检查函数。如果你使用On Changed,它会触发他们输入的每一个字符,所以如果Lines数组变得非常大,它可能会引入明显的延迟。只需使用正则表达式验证每一行的格式是否有效。。当然,使用所有双值,设置
roundToValue=2.5
,并将比较结果设置为1.0
,而不是100
。Hey@technonaut和Jimi感谢您的回答。