I am learning about event handlers and delegates. I have a single form with 4 text boxes and a list box. I'd like to have a delegate that listens for text box changes to ANY of the 4 boxes. The method associated with the delegate would simply be a method that takes the text value of the text box that changed, and add that as a new list item. My question is how to write the delegate to listen to all of the text boxes, and when I call the function to add the list box item, how can I pass in the text box object since I won't know explicitly which one raised the event? Will this be contained in the EventArgs e?
Rather than use multiple event handlers:
this.textBo1.TextChanged += txt_TextChanged;
this.textBo2.TextChanged += txt_TextChanged;
this.textBo3.TextChanged += txt_TextChanged;
this.textBo4.TextChanged += txt_TextChanged;
I'd like something like:
public delegate ListenToTextBoxes(object sender, EventArgs e);
Maybe that doesn't make sense since I'm new to delegates, but it seems reasonable to me that I should be able to make one delegate listen to text box controls in general, and then when it raises the event I cast the object sender and get the text box text. But how do I create the delegate so it listens ONLY to text boxes, or other types of controls?