文本输入框中只允许某些值
Only certain values are allowed in the text entry box
您是否看到程序的用户只能在文本输入框中输入特定数字的可能性?
示例:
14785(,00)
14787,50
14790(,00)
所以这个例子大约是2.5步。也可以有其他步骤,例如1.5步。进一步的要求是 1) 德语表示法(,
作为小数点分隔符)和 2) 只有正数。我已经有了。
由于这个网格,我不能使用 numeric up-down control
并且模数不适合 double
。
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
我解决了这个问题。我将输入的 Double 值乘以 10.0,然后将其转换为 Long
。然后我用Modulo
检查除以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
您是否看到程序的用户只能在文本输入框中输入特定数字的可能性? 示例:
14785(,00)
14787,50
14790(,00)
所以这个例子大约是2.5步。也可以有其他步骤,例如1.5步。进一步的要求是 1) 德语表示法(,
作为小数点分隔符)和 2) 只有正数。我已经有了。
由于这个网格,我不能使用 numeric up-down control
并且模数不适合 double
。
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
我解决了这个问题。我将输入的 Double 值乘以 10.0,然后将其转换为 Long
。然后我用Modulo
检查除以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