日期:2014-05-17 浏览次数:20776 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.ComponentModel;
namespace ConsoleApplication1
{
class Button
{
private event EventHandler click;
public event EventHandler Click
{
add { click += value; }
remove { click -= value; }
}
public void foo() { click(this, new EventArgs()); }
}
class Program
{
static void Main(string[] args)
{
Button btn = new Button();
btn.Click += new EventHandler(btn1_Click1);
btn.Click += new EventHandler(btn1_Click1);
btn.Click += new EventHandler(btn1_Click2);
btn.Click += new EventHandler(btn1_Click3);
Console.WriteLine("raise event by itself:");
btn.foo();
Console.WriteLine("raise event manually:");
EventHandler eh = btn.GetType().GetField("click", BindingFlags.Instance
------解决方案--------------------
BindingFlags.NonPublic).GetValue(btn) as EventHan