I am implementing an Error Provider in a C# WinForms app. By default, when the form opens, a textbox that has a validating method is on focus and I can't switch focus to any other control in the form, including the 'Cancel' button that I have.
private void TxtUsername_Validating(object sender, CancelEventArgs e)
{
e.Cancel = true;
errorProvider.SetIconPadding(control, 5);
errorProvider.SetError(control, "Required field");
}
What I am actually trying to add is the possibility to click the Cancel button while textbox is still on focus (i.e. to close the form), but it doesn't let me due to the Error Provider that is present there.
Is there a way to implement this in the app or the only way to do it is by removing the Error Provider?