Errorprovider shows error on using windows close button(X)

Posted by Pankaj Kumar on Stack Overflow See other posts from Stack Overflow or by Pankaj Kumar
Published on 2010-03-20T02:45:36Z Indexed on 2010/03/20 2:51 UTC
Read the original article Hit count: 558

Hi guys,

Is there any way to turn the damned error provider off when i try to close the form using the windows close button(X). It fires the validation and the user has to fill all the fields before he can close the form..this will be a usability issue because many tend to close the form using the (X) button.

i have placed a button for cancel with causes validation to false and it also fires a validation.

i found someone saying that if you use Form.Close() function validations are run... how can i get past this annoying feature.

i have a MDI sturucture and show the form using

 CreateExam.MdiParent = Me
        CreateExam.Show()

on the mdi parent's menuitem click

and have this as set validation

Private Sub TextBox1_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
        If String.IsNullOrEmpty(TextBox1.Text) Then
            Err.SetError(TextBox1, "required")
            e.Cancel = True
        End If
        If TextBox1.Text.Contains("'") Then
            Err.SetError(TextBox1, "Invalid Char")
            e.Cancel = True
        End If
    End Sub

Any help is much appreciated. googling only showed results where users were having problem using a command button as close button and that too is causing problem in my case

© Stack Overflow or respective owner

Related posts about winforms

Related posts about errorprovider