I am coding a C# Forms application and I have a question about validating a form.
I have a textbox
called textBoxCodeToSearchFor
that I want to validate when I press a button. If the textbox
does not have any text in it, I need a tooltip
to be shown.
Here is my code:
private void textBoxCodeToSearchFor_Validating(object sender, CancelEventArgs e)
{
if (String.IsNullOrEmpty(textBoxCodeToSearchFor.Text))
{
e.Cancel = true;
toolTip.Show("Please enter the code to search for", textBoxCodeToSearchFor);
}
}
On the button click I have the following code:
bool validated = this.Validate();
The tooltip
is then shown, however, I cannot close the form when pressing a cancel button.
How can I shown a tooltip
for a textbox
if the textbox
does not validate, but still close out of the form is wanted?
Thanks in advance.