首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

使用datatimepicker的有关问题

2012-01-28 
使用datatimepicker的问题form里有两个控件,一个TextBox TextBox1 还有一个DataTimePicker dtpVB.NET code

使用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]
r.White
  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 

热点排行