**** Merged from MCS ****
[mono-project.git] / mcs / tests / test-57.cs
blob2d23bdedb13226fd85ae90f3576e1ad82e033672
1 using System;
3 public delegate void EventHandler (int i, int j);
5 public class Button {
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)
16 if (click == null) {
17 Console.WriteLine ("Nothing to click!");
18 return;
21 click (i, j);
24 public void Reset ()
26 click = null;
30 public class Blah {
32 Button Button1 = new Button ();
34 public void Connect ()
36 Button1.Click += new EventHandler (Button1_Click);
37 Button1.Click += new EventHandler (Foo_Click);
40 public void Button1_Click (int i, int j)
42 Console.WriteLine ("Button1 was clicked !");
43 Console.WriteLine ("Answer : " + (i+j));
46 public void Foo_Click (int i, int j)
48 Console.WriteLine ("Foo was clicked !");
49 Console.WriteLine ("Answer : " + (i+j));
52 public void Disconnect ()
54 Console.WriteLine ("Disconnecting Button1's handler ...");
55 Button1.Click -= new EventHandler (Button1_Click);
58 public static int Main ()
60 Blah b = new Blah ();
62 b.Connect ();
64 b.Button1.OnClick (2, 3);
66 b.Disconnect ();
68 Console.WriteLine ("Now calling OnClick again");
69 b.Button1.OnClick (3, 7);
71 Console.WriteLine ("Events test passes");
72 return 0;