Is there a way to force a tooltip to show?
"If the field cannot be validated, i have it clearing the box and marking it red. I would also like it to pop up a tooltip over the box saying that the value is invalid."
From the description of the behavior that you want, it sounds like you would be best served by the ErrorProvider
component rather than a tooltip. The ErrorProvider
component will automatically place an icon you specify next to the control that failed validation and display a tooltip to the user describing the validation error and/or the steps they need to take to correct it:
There is a sample available on C# Corner, but it's very simple to implement. Simply add an ErrorProvider
component to your form (it's available by default in the toolbox), then in your validation method, write the following code:
private void ValidateName()
{
if (string.IsNullOrEmpty(NameTextBox.Text))
{
//Validation failed, so set an appropriate error message
errorProvider.SetError(NameTextBox, "You must enter your name");
}
else
{
//Clear previous error message
errorProvider.SetError(NameTextBox, string.Empty);
}
}
Try this:
Basically,
private void button1_Click(object sender, EventArgs e)
{
ToolTip toolTip1 = new ToolTip();
toolTip1.Title = "Invalid entry"; // Title to display.
toolTip1.Show("Please enter a number.", textBox1); // Message of the toolTip and to what control to appear.
}
But there are 5 other overloads for ToolTip. You can see it here.