Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Events
Message
 
À
14/11/2004 11:32:23
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Titre:
Re: Events
Divers
Thread ID:
00961252
Message ID:
00961265
Vues:
7
Thanks Bonnie!

Does this meen i have to put all this code in the form everytime i add a object to it ? I would like to code this in a subclass of a textbox and everytime i would add this textbox to a form it would susbcribe to the event of the form without adding code to the form... Is this possible ?


>Stephane,
>
>I have a simple example that I typically use for explaining this, but I've modified it a bit to fit what you're asking about:
>
>Here is the Custom Event on your form, you need the following things:
>
>// First you must make a public EventHandler:
>public event EventHandler MyEvent;
>
>// Then you need this code to raise the MyEvent event:
>protected virtual void OnMyEvent(EventArgs e)
>{
>	if (MyEvent != null)
>		MyEvent(this, e);
>}
>
>Then, your TextBoxes would need to have the usual delegates and EventHandlers for the KeyPress event:
>
>this.MyTextBox.KeyPress += new KeyPressEventHandler(this.MyTextBox_KeyPressHandler);
>
>protected virtual void KeyPressHandler(object sender, KeyPressEventArgs e)
>{
>    // Here is where you need to fire your Custom event:
>    this.OnMyEvent(new EventArgs());
>}
>
>// And all other controls that need to subscribe to the event would have
>// the usual delegates and EventHandlers:
>this.MyLabel.MyEvent += new System.EventHandler(this.MyLabel_MyEventHandler);
>
>private void MyLabel_MyEventHandler(object sender, System.EventArgs e)
>{
>	// whatever your code needs to be
>}
>
>Hope this helps.
>
>~~Bonnie
>
>
>
>>Hi all, i've been browsing documentation for a few days now and i'm still unclear about all this events and delegates thingny. What i'd like to see is a simple form example doing the following:
>>
>>a form with 1 label and 2 textbox. when the keypress event of one the textbox is fired, all other object are notified by suscribing to a custom event of the form. The code for the event handling would be in the derived class of the textbox and the label.
>>
>>Thanks.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform