First of all I just picked up C# a few days ago, so I am green as grass. The problem I am having is with the TextChange event. I am trying to get the name of the text box that this event came from. Here is a sample of my code.
myTextBox.TextChanged +=
new EventHandler(textBoxChanged);private
void textBoxChanged(object sender, EventArgs e){
//This is where I need to know what textbox fired the event.
}
How do I send the name to this? Any thoughts? I might not even be approaching this properly. I also checked out some custom event handlers, but being new, it's a nightmare.
Thanks in advance,
Chris
ChrisPosted Aug 23, 2007, 6:29 PM
AlanPosted Aug 23, 2007, 6:00 PM
The 'sender' parameter represents the TextBox object whose Text property has changed. You can get a usable reference to it like this:
TextBox tb = (TextBox)sender;
You need to cast sender to TextBox because sender is declared as an Object.
You can then get the name of the TextBox like this:
string name = tb.Name;