原文: http://social.microsoft.com/Forums/zh-CN/visualcshartzhchs/thread/9211ba35-001f-4319-a8e6-96e53995fbf9
private
void
Form1_Load(
object
sender, EventArgs e)
{
this
.button1.Click +=
delegate
(
object
a, EventArgs b)
{
MessageBox.Show(
"Test!"
);
};
}
private
void
button2_Click(
object
sender, EventArgs e)
{
Type t = button1.GetType();
PropertyInfo pi = t.GetProperty(
"Events"
, BindingFlags.Instance | BindingFlags.NonPublic);
EventHandlerList ehl = (EventHandlerList)pi.GetValue(button1,
null
);
FieldInfo fieldInfo = (
typeof
(Control)).GetField(
"EventClick"
, BindingFlags.Static | BindingFlags.NonPublic);
Delegate d = ehl[fieldInfo.GetValue(
null
)];
if
(d !=
null
)
{
foreach
(Delegate temp
in
d.GetInvocationList())
{
ehl.RemoveHandler(fieldInfo.GetValue(
null
), temp);
}
}
}