OK you already know how to add a event handler to the TextChanged event and I'm guessing you also know that if you specify the same method name in this case
txt_TextChanged
then all the then they would use the same method to process the TextChanged event, such as;
void txt_TextChanged(object sender, EventArgs e)
{
TextBox textBox = sender as TextBox;
}
If you want to use a separate class to process all TextChanged events you can also do that.
If you create a class like the following (remember to add
using System.Windows.Forms;
to the class);
public class TextChangeHandler
{
public void TextChanged(object sender, EventArgs e)
{
TextBox textBox = sender as TextBox;
}
}
you can then use the following to handle the TextChanged event;
TextChangeHandler txtChangeHandler = new TextChangeHandler();
textBox1.TextChanged += new EventHandler(txtChangeHandler.TextChanged);
textBox2.TextChanged += new EventHandler(txtChangeHandler.TextChanged);
textBox3.TextChanged += new EventHandler(txtChangeHandler.TextChanged);
You can also make the class static and use;
public static class TextChangeHandler
{
public static void TextChanged(object sender, EventArgs e)
{
TextBox textBox = sender as TextBox;
}
}
you can then use the following to handle the TextChanged event;
textBox1.TextChanged += new EventHandler(TextChangeHandler.TextChanged);
textBox2.TextChanged += new EventHandler(TextChangeHandler.TextChanged);
textBox3.TextChanged += new EventHandler(TextChangeHandler.TextChanged);