TextBox tb = sender as TextBox;
if (tb != null)
{
EventHandlerList events = (EventHandlerList)typeof(Control).GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(tb, null);
object key = typeof(Control).GetField("EventKeyPress", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
var tbEvent = events[key];
if (tbEvent != null)
{
var invokeLst = tbEvent.GetInvocationList();
if (invokeLst != null && invokeLst.FirstOrDefault() != null &&
Delegate.Equals(invokeLst.FirstOrDefault(), new KeyPressEventHandler(txtNumericOnly_KeyPress)))
{
ShowFieldValidationError(tb, CommonFunctions.OnlyAllowNumericEntry(tb, false, NumericValueType.Int32));
}
if (invokeLst != null && invokeLst.FirstOrDefault() != null &&
Delegate.Equals(invokeLst.FirstOrDefault(), new KeyPressEventHandler(txtDecimalOnly_KeyPress)))
{
ShowFieldValidationError(tb, CommonFunctions.OnlyAllowNumericEntry(tb, true, NumericValueType.Decimal));
}
}
}
GetInvocationList
最新推荐文章于 2021-06-29 00:44:31 发布