[英]Masked textbox issue in VB.NET
I have two masked textboxes that have validation if they are valid dates. 我有两个带掩码的文本框,如果它们是有效日期,则它们具有验证。
Here is the code for the event of the two controls. 这是两个控件的事件代码。
Private Sub txtCutOff_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) _
Handles txtCutOff.KeyDown
If e.KeyCode = Keys.Enter Then
txtPayPeriod.Focus()
txtPayPeriod.SelectAll()
End If
End Sub
Private Sub txtCutOff_Leave(sender As Object, e As System.EventArgs) _
Handles txtCutOff.Leave
If isClosing = False And isAddEdit And btnCancel.Focused = False Then
If txtCutOff.Text.Contains(" ") Or txtCutOff.Text.Length <> 10 Then
MessageBox.Show("Enter Valid Cut Off Date", _
"RMI", _
MessageBoxButtons.OK, _
MessageBoxIcon.Warning)
txtCutOff.SelectAll()
txtCutOff.Focus()
isField_Empty = True
Else
' Get date details
get_DateDetails(txtCutOff.Text)
If IsDate("#" & sMonth & "/" & sDay & "/" & sYear & "#") = False Then
MessageBox.Show("Enter Valid Cut Off Date", _
"RMI", _
MessageBoxButtons.OK, _
MessageBoxIcon.Warning)
txtCutOff.SelectAll()
txtCutOff.Focus()
isField_Empty = True
Else
isField_Empty = False
End If
End If
End If
End Sub
Private Sub txtPayPeriod_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) _
Handles txtPayPeriod.KeyDown
If e.KeyCode = Keys.Enter Then
txtSewers.Focus()
txtSewers.SelectAll()
End If
End Sub
Private Sub txtPayPeriod_Leave(sender As Object, e As System.EventArgs) _
Handles txtPayPeriod.Leave
If isClosing = False And isAddEdit And btnCancel.Focused = False Then
If txtPayPeriod.Text.Contains(" ") Or txtPayPeriod.Text.Length <> 10 Then
MessageBox.Show("Enter Valid Cut Off Date", _
"RMI", _
MessageBoxButtons.OK, _
MessageBoxIcon.Warning)
txtPayPeriod.SelectAll()
txtPayPeriod.Focus()
isField_Empty = True
Else
' Get date details
get_DateDetails(txtPayPeriod.Text)
If IsDate("#" & sMonth & "/" & sDay & "/" & sYear & "#") = False Then
MessageBox.Show("Enter Valid Cut Off Date", _
"RMI", _
MessageBoxButtons.OK, _
MessageBoxIcon.Warning)
txtPayPeriod.SelectAll()
txtPayPeriod.Focus()
isField_Empty = True
Else
isField_Empty = False
End If
End If
End If
End Sub
Here is my code for checking the valid date: 这是我用于检查有效日期的代码:
Sub get_DateDetails(strDate)
' Get month
sMonth = strDate.Remove(0, 5)
sMonth = sMonth.Remove(2, 3)
' Get day
sDay = strDate.Remove(0, 8)
' Get year
sYear = strDate.Remove(4, 6)
End Sub
When I am testing the valid date and enter value "1212", and I press enter, it prompts the user that the date is not valid, and then when I enter the value "1212" again, the output is not the same. 当我测试有效日期并输入值“ 1212”,然后按Enter键时,它会提示用户该日期无效,然后再次输入值“ 1212”时,输出将不相同。 It removes the first character that I entered, and the value now is " 212".
它删除了我输入的第一个字符,现在的值为“ 212”。
There are no problems when I enter the value "1212" and click the other control. 输入值“ 1212”并单击另一个控件时,没有问题。 It will validate that the date is not valid, because it leaves the control and do the code behind using the Leave event, but when I always press keydown, it always removes the first character that I entered.
它将验证日期无效,因为它会离开控件并使用Leave事件处理代码,但是当我始终按下keydown时,它将始终删除我输入的第一个字符。
尝试使用jQuery插件掩盖日期。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.