一定要注意messagebox语句出现的位置

        今天来了一份新的buglist,其中一条是:日起不正确时报多个messagebox。我察看了一下源程序,问题源代码如下:

Private Sub Object1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Object1.GotFocus,Object2.GotFocus,Object2.GotFocus

        If IsDate(Date1.Text) = False Then
            lblWeekday.Text = "()"
            MessageBox.Show("入金日が正しくありません。", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
            Date1.Focus()

        Else
            lblWeekday.Text = "(" + DateAndTime.WeekdayName(Weekday(CDate(Date1.Text))) + ")"
        End If

End Sub

 

        问题出在橙色代码上。.net执行完MessageBox.Show后,程序便就此终止,后面的语句Date1.Focus()便不再执行,于是焦点一直停留在Object1中,引发不停的报message的情况

        我对代码进行如下修改(调换了一下两个语句的顺序),问题便解决了。

Private Sub Object1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Object1.GotFocus,Object2.GotFocus,Object2.GotFocus

        If IsDate(Date1.Text) = False Then
            lblWeekday.Text = "()"
            Date1.Focus()
            MessageBox.Show("入金日が正しくありません。", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            lblWeekday.Text = "(" + DateAndTime.WeekdayName(Weekday(CDate(Date1.Text))) + ")"
        End If

End Sub

 

        大家在使用messagebox的时候要小心喽~~

你可能感兴趣的:(一定要注意messagebox语句出现的位置)