I’m a bit new to windows forms so I apologize if there is a simple solution, but I can’t find anything on google. If I drag an item, for instance a textbox, onto the form, and double click it, the textbox_TextChanged function will be created for me. This works as expected. However, if I attempted to add a new function such as textbox_Click, it will never be called. In another project, I attempted to add a textbox_Validating function and it isn’t being called either (I made sure validating was on in the properties).
Does anyone know why only the TextChanged function is being called?
Here is what is working:
private void textBox2_TextChanged(object sender, EventArgs e)
{
textBox2.BackColor = activeColor;
}
Here is what isn’t working:
private void textBox2_Click(object sender, EventArgs e)
{
textBox2.BackColor = activeColor;
}
I’ve set a breakpoint in the textBox2_Click method and it is never being called. I’ve looked around the web and tried other methods such as _LeftMouseClick and _LeftMouseButtonDown but they aren’t working ether.
This also isn’t working:
protected void tbNewPassword_Validating(object sender, CancelEventArgs e)
{
if (tbNewPassword.Text.Length < 6)
epErrorProvider.SetError(tbNewPassword, "Your password must be 6 characters or longer.");
}
As with the _Click method, I’ve set a breakpoint and it is never being called.
select the textbox, open the property window, at the top, there is a small icon that looks like a lightning (there are some other icons at the top, 1 looks like ‘A to Z’), click it, it will show all the events. Scroll down, validating is at the end. Input the validating function name, hit return key, it will show validating function in the code. add your code in there.
This helps you add an event.
or, you need add event handler directly, something like