Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Delegates
Message
De
16/06/2003 16:24:29
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Divers
Thread ID:
00800062
Message ID:
00800512
Vues:
36
Jeff,

>>Does C# have a 'Handles' keyword as well?<

Nope, the code I posted is the way to do it in C#. Just different syntax in VB, that's all.

~~Bonnie


>Oops, that was simpler than I'd thought. Why couldn't I get hold of that?
>
>A way to do this in VB uses the 'Handles' keyword:
>
>Public Sub B_ButtonClick(Sender As Object, E As EventArgs) Handles B.Click
>  ...
>End Sub
>
>Does C# have a 'Handles' keyword as well?
>
>
>
>>Jeff,
>>
>>Briefly, a delegate tells .NET what method you want to use to handle an event. Say you have a button and you want it to do something when it's clicked.
>>
>>First you have to define the delegate, to tell .NET which method is your eventhandler:
>>
>>this.MyButton.Click += new System.EventHandler(this.MyButton_Click);
>>
>>... then you define the eventhandler method itself:
>>
>>private void MyButton_Click(object sender, System.EventArgs e)
>>{
>>    // code to handle the click goes here
>>}
>>
>>
>>~~Bonnie
>>
>>
>>>OK, OK... You get a few more <g>
>>>
>>>What's it all about? What's a delegate, and why would I use one?
>>>
>>>
>>>
>>>>>>Bonnie, could you explain delegates, in five words or less? <
>>>>
>>>>Sure ... "How one must handle events." Count 'em, that's 5 words. =)
>>>>
>>>>~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform