public partial class event_test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TestEvent te = new TestEvent();
te.TestPrint += new EventHandler(te_TestPrint);
te.Testp("10", null);
TestEvent2 te2 = new TestEvent2();
te2.Mt += new Mytestevent(te2_Mt);
te2.Testp("o", new NewEvent() { id="01",name="静"});
}
void te2_Mt(NewEvent nevent, object sender)
{
Response.Write(nevent.id + nevent.name);
}
void te_TestPrint(object sender, EventArgs e)
{
Response.Write("0");
}
}
public class TestEvent
{
object obj = new object();
public TestEvent()
{ }
private event EventHandler testprint;
public event EventHandler TestPrint
{
add
{
testprint += value;
}
remove
{
testprint -= value;
}
}
public void Testp(object sender, EventArgs e)
{
testprint(sender, e);
}
}
public class NewEvent : EventArgs
{
public string name { get; set; }
public string id { get; set; }
}
public delegate void Mytestevent(NewEvent nevent, object sender);
public class TestEvent2
{
object obj = new object();
private event Mytestevent mt;
public event Mytestevent Mt
{
add
{
mt += value;
}
remove
{
mt -= value;
}
}
public void Testp(object sender, NewEvent e)
{
mt(e, sender);
}
}