您的位置:首页 > 其它

GetInvocationList

2015-11-30 16:09 260 查看
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));
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: