使用datatimepicker的问题
form里有两个控件,一个TextBox TextBox1 还有一个DataTimePicker dtp
- VB.NET code
' 当焦点离开text时进行检查,看其有没有入力,如果没有入力则报个messaege,并将背景色设成黄色。 Private Sub TextBox1_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating TextBox1.BackColor = Colo[code=VB.NET]
If TextBox1.Text.Length = 0 Then
TextBox1.Select()
TextBox1.BackColor = Color.Yellow
MsgBox("1001")
e.Cancel = True
End If
End Sub[/code]
但是当点那个DatatimePicker的时候,会报两遍错。若是把DatatimePicker换成别的控件如textbox,combobox则都没问题。
请问怎么回事?
[解决办法]
- VB.NET code
Private Sub TextBox1_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating If TextBox1.Text.Length = 0 Then TextBox1.BackColor = Color.Yellow MsgBox("1001") e.Cancel = True End If End Sub