1 Replies - 345 Views - Last Post: 16 September 2012 - 09:23 PM Rate Topic: -----

#1 ilakkiaselvan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-September 12

Events with delegates

Posted 16 September 2012 - 07:52 PM

HI all,

I was trying hard to understand events & Delegates in C#. I Dont know y it is so difficult to understand this. Please have a look at the code here.

Please explain me what exactly happens in this
 theClass3.myEvent += new EventPublisher.EventDelegate(this_onprogress);


please re write the above code without "+=" so that i can visualize what exactly happens there.

Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Events with delegates

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5628
  • View blog
  • Posts: 12,075
  • Joined: 02-June 10

Re: Events with delegates

Posted 16 September 2012 - 09:23 PM

You don't re-write without that. That's how you subscribe to an event. You are adding a subscription to an event.

If you look in the designer.cs file for a form with a button.click event on it you'll see the same syntax. Just make a form. Drag a button on it. Double-click the button to have VS make a subscription and a handler for you. Now open the designer.cs file and you'll see VS did it the same way.

Within the class theClass3 is an event called .myEvent

You are wiring up a handler to that event: Subscribing to the event, and naming this_onpregress as the handler.

Maybe this article of mine will help clear your confusion:
Quick and easy custom events
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1