【发布时间】:2010-10-09 13:59:06
【问题描述】:
我试图想出一种方法来轻松检测是否对 Winform 上的控件进行了更改。这种方法有效,但它没有提供有关哪些控件已更改的信息。有没有办法覆盖 TextChanged 事件,以便它通过,而 EventArg 包含触发事件的控件的名称?当 AccountChangedHandler 执行时,sender 参数包含有关文本框的信息,例如“.Text”属性的当前值,但我看不到有关哪个控件引发事件的任何信息。
private bool _dataChanged = false;
internal TestUserControl()
{
InitializeComponent();
txtBillAddress1.TextChanged += new System.EventHandler(AccountChangedHandler);
txtBillAddress2.TextChanged += new System.EventHandler(AccountChangedHandler);
txtBillZip.TextChanged += new System.EventHandler(AccountChangedHandler);
txtBillState.TextChanged += new System.EventHandler(AccountChangedHandler);
txtBillCity.TextChanged += new System.EventHandler(AccountChangedHandler);
txtCountry.TextChanged += new System.EventHandler(AccountChangedHandler);
txtContactName.TextChanged += new System.EventHandler(AccountChangedHandler);
txtContactValue1.TextChanged += new System.EventHandler(AccountChangedHandler);
txtContactValue2.TextChanged += new System.EventHandler(AccountChangedHandler);
txtContactValue3.TextChanged += new System.EventHandler(AccountChangedHandler);
txtContactValue4.TextChanged += new System.EventHandler(AccountChangedHandler);
}
private void AccountChangedHandler(object sender, EventArgs e)
{
_dataChanged = true;
}
【问题讨论】: