Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Delegates
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Divers
Thread ID:
00800062
Message ID:
00800644
Vues:
28
>Whew, that's a mouthful! I think I understand what you say here, though -- would you happen to have a little code sample handy to help finish it off?
>

Ok, actually, if you have Visual Studio it writes the code for you...

1. Create a new C# Windows application call it SandBox.

2. You will be presented with Form1.

3. Drop a textbox onto the form and a button.

4. Double-click on the button and you will be brought to the editor to a method of the form named button1_click().

5. Put code into the method of this.textbox1.Text = "Button Pressed"

Now, how does this method of the form get fired?

Well, expand the code above that is the generate code... you will see this line:

this.button1.Click += new System.EventHandler(this.button1_Click);

This creates a Delegate (object) which will call this.button1_Click and registers it with the Click event. Now, this event could have been an event you defined on a custom class you wrote.

Anyway, when the click even fires it calls the delagate which calls the method it is pointed to. The button1_Click runs and the text in the textbox is changed. You can run this and test it.

Clear as mud?

BOb
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform