-1
我不能得到以下vb.net代码太工作。我试图达到的目标是限制在3和6之间使用的数字。如果用户输入的值小于3,文本框将值更正为3,并且用户输入的值大于6,则文本框值已更改为6 ...Autocorrecting文本框输入(vb.net代码)
Select Case e.KeyChar
Case "3", "4", "5", "6", vbBack
e.Handled = False
Case Else
e.Handled = True
If TextBox27.Text <= 2 Then
MessageBox.Show("Minimum of 3 loads permissible", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information)
TextBox27.Text = "3"
TextBox27.Focus()
ElseIf TextBox27.Text >= 7 Then
'Shows error message...
MessageBox.Show("Maximum of 6 loads permissible", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information)
TextBox27.Text = "6"
TextBox27.Focus()
End If
End Select
是的尝试,但我仍然有同样的问题,如果我1型或2文本框作出响应,预期...但是如果我在任何类型lagrger比6 texbox剂量没有反应.. –
这是因为' TextBox27.Text> =“7”'永远不会是真的。该框只接受小于7的字符。您正在进行的文本比较评估字母顺序。也许你应该将TextBox27.Text转换为一个整数,然后比较为7(不带引号。 – JerryM