Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Inherited label class and mouse events
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00873386
Message ID:
00873478
Vues:
24
The event delegation model is great for the situation where one object wants to get notified of events happening inside another object (a form listens to the button's click event). In this case, the listener and the source of the event are the same object so the label already knows about the events that it is raising through the OnEventname methods.

It may be slightly more efficient because there is not the overhead of maintaining the invocation list and calling the delegate but I think the real reasons are that it is easier to override these protected methods if you are going to further subclass the control and it keeps the control just more logically self contained.

So the rule of thumb would be if you are using inheritance then override the OnMethodname. When one object is listening to the events inside another object then use the delegation model.


>Dave,
>
>Not looking for an argument (some might say I tend to argue a lot <g>), but I'm just curious ... the documentation you quoted says:
>
>"The OnMouseDown method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class."
>
>I'm just wondering what the pros and cons are of using the OnWhateverEvent vs using a delegate (as I suggested to Steve). IOW, any idea why this would be the preferred technique? I'm guessing that maybe it's more efficient, but I really don't know ...
>
>~~Bonnie
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform