From: Jackie on 30 May 2010 12:05 Do you mean something like this? ----- MyEvent = new MyEventHandler( (sender_, e_) => { throw new NotImplementedException(); }); MyEvent.Invoke(this, EventArgs.Empty); -----
From: Jackie on 30 May 2010 12:06 Or just... ----- if (MyEvent != null) { MyEvent.Invoke(this, EventArgs.Empty); } -----
From: Tony Johansson on 30 May 2010 12:46 "Arne Vajh�j" <arne(a)vajhoej.dk> skrev i meddelandet news:4c0285f8$0$286$14726298(a)news.sunsite.dk... > On 30-05-2010 11:09, Tony Johansson wrote: >> "Arne Vajh�j"<arne(a)vajhoej.dk> skrev i meddelandet >> news:4c027933$0$274$14726298(a)news.sunsite.dk... >>> On 30-05-2010 10:31, Tony Johansson wrote: >>>> Here is some code. But the code marked with * below how would that >>>> //Create a delegete >>>> public delegete void MyEventHandler(object sender, EventArgs e); >>>> >>>> //Create an event member >>>> public event MyEventHandler MyEvent; >>>> >>>> //Invoke the delegete within a method when you need to raise the event, >>>> as >>>> the following code demonstrates >>>> >>>> if(MyEvent != null) >>>> MyEvent((this, EventArgs.Empty) >>>> >>>> EventArgs e = new EventArgs(); >>>> >>>> if (handler != null) >>>> handler(this, e); >>> >>> I do not see the * !?!? >> >> Sorry >> >> I mean these lines. >> if (handler != null) >> handler(this, e); > > Should handler be MyEvent or ? > > Arne > In the book I read it says the following. How to raise an event. 1. Create a delegete public delegate void MyEventHandler 2.Create an event member public event MyEventHandler MyEvent 3.Invoke the delegete within a method when you need to raise the event, as the following code demonstrates if (MyEvent != null) MyEvent(this, EventArgs.Empty); EventArgs e = new EventArgs(); if (handler != null) { //invoke the delegete handler(this != null); } I understand everything except the following if (handler != null) { //invoke the delegete handler(this != null); } I don't understand what the book wants to says when they already has this text if (MyEvent != null) MyEvent(this, EventArgs.Empty); Do they want to says that the event can be called handler instead of MyEvent ? //Tony
From: Willem van Rumpt on 30 May 2010 13:34 On 30-5-2010 18:05, Jackie wrote: > Do you mean something like this? > ----- > MyEvent = new MyEventHandler( > (sender_, e_) => > { > throw new NotImplementedException(); > }); > MyEvent.Invoke(this, EventArgs.Empty); > ----- Tell Tony ;) -- Willem van Rumpt
From: Jackie on 30 May 2010 13:39 On 5/30/2010 19:34, Willem van Rumpt wrote: > On 30-5-2010 18:05, Jackie wrote: >> Do you mean something like this? >> ----- >> MyEvent = new MyEventHandler( >> (sender_, e_) => >> { >> throw new NotImplementedException(); >> }); >> MyEvent.Invoke(this, EventArgs.Empty); >> ----- > > Tell Tony ;) > Oh yeah, seems like I replied to you instead.
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Transparent form with hourglass? Next: SQLSiteMapProvider with a parameter problem |