//sets subject, button, random object public Observer(SubjectWithEvent subject, String observerName, Button buttonToClick, Random random) { this.subject = subject; this.observerName = observerName; this.random = random; buttonString = buttonToClick.ToString(); //adds delegate instance containing "DoStuff" to the buttons click event buttonToClick.Click += new System.EventHandler(DoStuff); }
public Form1() { InitializeComponent(); random = new Random(); subjectWithEvent = new SubjectWithEvent(); //creates observers (already bound to button.Click) observer1 = new Observer(subjectWithEvent, "One", buttonTestHandlers, random); observer2 = new Observer(subjectWithEvent, "Two", buttonTestHandlers, random); }