void AccountChangedHandler(object sender, EventArgs e) { string n = ((TextBox)sender).Name; string t = ((TextBox)sender).Text; // or instead of cast TextBox tb = sender as TextBox; // if sender is another type, tb is null if(tb != null) { string n = tb.Name; string t = tb.Text; } }
你也可以尝试使用
foreach (Control c in this.Controls) { c.TextChanged += new EventHandler(AccountChangedHandler); }