G
Guest
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 'causesvalidation'
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
'causesvalidation' property is False. The following code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
e.Cancel = False
End Sub
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
If TextBox1.Text.Length < 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 causesvalidation
to False, then the escape key works! This sounds (looks) like a bug to me.
that I don't find documented anywhere. It has to do with 'causesvalidation'
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
'causesvalidation' property is False. The following code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
e.Cancel = False
End Sub
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
If TextBox1.Text.Length < 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 causesvalidation
to False, then the escape key works! This sounds (looks) like a bug to me.