//Create a new bidder object and subscribe to its events private void CreateNewBidder() { string bidderName = ReadBidderName(); //Create the new bidder if (!string.IsNullOrEmpty(bidderName)) { BidderIsPublisher frm = new BidderIsPublisher(txtName.Text, m_newBidObject.Name); frm.Show(); //Subscribe to the publisher's new bid and quit bid events frm.NewBid += OnNewBidSent; frm.QuitBid += OnBidderDrawBack; } }
/// <summary> /// Here is the power of delegates - who is the bidder - don't know, /// the sender tells us at run time /// Eventhandler for the sender's (bidder's) SendQuitBid event - what to do when the event is /// fired by the publisher object (a bidder class, see above) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// private void OnBidderDrawBack(object sender, BidEventInfo e) { lstBidHistory.Items.Add(string.Format("{0} draws back at {1}. Please come back!", e.Bidder, DateTime.Now.ToShortTimeString())); if (sender != null) { BidderIsPublisher frm = (BidderIsPublisher)sender; //Unubscribe to the publisher's new bid and quit bid events //Compare with above (subscription) frm.NewBid -= OnNewBidSent; frm.QuitBid -= OnBidderDrawBack; frm.Title = "You are out! " + DateTime.Now.ToShortTimeString(); } }