3 public delegate void EventHandler (int i
, int j
);
7 private EventHandler click
;
9 public event EventHandler Click
{
10 add { click += value; }
11 remove { click -= value; }
14 public void OnClick (int i
, int j
)
17 Console
.WriteLine ("Nothing to click!");
32 Button Button1
= new Button ();
34 public void Connect ()
36 Button1
.Click
+= new EventHandler (Button1_Click
);
37 Button1
.Click
+= new EventHandler (Foo_Click
);
38 Button1
.Click
+= null;
41 public void Button1_Click (int i
, int j
)
43 Console
.WriteLine ("Button1 was clicked !");
44 Console
.WriteLine ("Answer : " + (i
+j
));
47 public void Foo_Click (int i
, int j
)
49 Console
.WriteLine ("Foo was clicked !");
50 Console
.WriteLine ("Answer : " + (i
+j
));
53 public void Disconnect ()
55 Console
.WriteLine ("Disconnecting Button1's handler ...");
56 Button1
.Click
-= new EventHandler (Button1_Click
);
59 public static int Main ()
65 b
.Button1
.OnClick (2, 3);
69 Console
.WriteLine ("Now calling OnClick again");
70 b
.Button1
.OnClick (3, 7);
72 Console
.WriteLine ("Events test passes");