I have noiticed a change in behavior between VB6 and VB.Net (2003 and 2005)
that I don't find documented anywhere. It has to do with 'causesvalidati on'
and the button on the Form defined to be the cancelbutton. According to the
documentation: "The cancel button for a form is the button control that is
clicked whenever the user presses the ESC key." Yet 'clicking' the button
and pressing the escape key do not produce the same results. Simple example:
One textbox, 1 button, the button is the forms 'cancelbutton', the buttons
'causesvalidati on' property is False. The following code:
Public Class Form1
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Me.Close()
End Sub
Private Sub Form1_FormClosi ng(ByVal sender As Object, ByVal e As
System.Windows. Forms.FormClosi ngEventArgs) Handles Me.FormClosing
e.Cancel = False
End Sub
Private Sub TextBox1_Valida ting(ByVal sender As Object, ByVal e As
System.Componen tModel.CancelEv entArgs) Handles TextBox1.Valida ting
If TextBox1.Text.L ength < 5 Then
e.Cancel = True
End If
End Sub
End Class
Clicking the button works, tabing to the button and pressing the spacebar
works, closing the form from the controlbox works .... pressing the escape
button does NOT work! Surprisingly, if I change the TextBox causesvalidatio n
to False, then the escape key works! This sounds (looks) like a bug to me.
--
Terry
that I don't find documented anywhere. It has to do with 'causesvalidati on'
and the button on the Form defined to be the cancelbutton. According to the
documentation: "The cancel button for a form is the button control that is
clicked whenever the user presses the ESC key." Yet 'clicking' the button
and pressing the escape key do not produce the same results. Simple example:
One textbox, 1 button, the button is the forms 'cancelbutton', the buttons
'causesvalidati on' property is False. The following code:
Public Class Form1
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Me.Close()
End Sub
Private Sub Form1_FormClosi ng(ByVal sender As Object, ByVal e As
System.Windows. Forms.FormClosi ngEventArgs) Handles Me.FormClosing
e.Cancel = False
End Sub
Private Sub TextBox1_Valida ting(ByVal sender As Object, ByVal e As
System.Componen tModel.CancelEv entArgs) Handles TextBox1.Valida ting
If TextBox1.Text.L ength < 5 Then
e.Cancel = True
End If
End Sub
End Class
Clicking the button works, tabing to the button and pressing the spacebar
works, closing the form from the controlbox works .... pressing the escape
button does NOT work! Surprisingly, if I change the TextBox causesvalidatio n
to False, then the escape key works! This sounds (looks) like a bug to me.
--
Terry
Comment