I have a validating event
private void EmployeeIDtextBox_Validating(object sender, CancelEventArgs e)
{
if (EmployeeIDtextBox.Text == "")
{
MessageBox.Show("Please Enter EmployeeID.", "Invalid EmployeeID");
}
}
And able to skip the validation with a cancelbutton
private void cancelbutton_Click(object sender, EventArgs e)
{
AutoValidate = AutoValidate.Disable;
Close();
}
Is it possible to skip validation with controlbox[X] of windowsform? I tried to set CausesValidation of form to false but it is not working. I also try it with formclosing but is it not working.
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (EmployeeIDtextBox.CausesValidation)
{
EmployeeIDtextBox.CausesValidation = false;
Close();
}
}
I already gave you the answer in your previous question. Stop using MessageBox and your problem disappears. Use the ErrorProvider component instead.
Intercepting the form's closing handling so you can cancel the validation before the first event fires requires a hack. Paste this code into your form:
protected override void WndProc(ref Message m) {
// Intercept WM_SYSCOMMAND, SC_CLOSE
if (m.Msg == 0x112 && (m.WParam.ToInt32() & 0xfff0) == 0xf060) this.AutoValidate = AutoValidate.Disable;
base.WndProc(ref m);
}