|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Handles keyword.I didn't use a "Handles" keyword in VB6. I can't sure its funciton. Does it mean that any object behind "handles" keyword will run the same code? ex: Private Sub A(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B, C, D, E // B , C, D, E objects will get the same message ? END SUB // Thank you very much! // BR // /Boki. bokit***@ms21.hinet.net wrote:
Show quoteHide quote > Hi All, B,C,D and E are Events of an object declared withevents> > I didn't use a "Handles" keyword in VB6. I can't sure its funciton. > > Does it mean that any object behind "handles" keyword will run the same > code? > > ex: > Private Sub A(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles B, C, D, E > > // B , C, D, E objects will get the same message ? > > > END SUB > e.g. - private withevents txtEdit as TextBox Declares a reference to a TextBox called txtEdit that has events associated with it (e.g. KeyPress). When you declare your event handler (say) Private Sub X(....) handles txtEdit.KeyPressed you are saying that the object that this refers to (created by txtEdit = new TextBox()) is acquiring a (possibly additional) handler for when it raises its KeyPress event. The same Event Handler can handle multiple events ; this might be used (say) if you had multiple text fields that you wanted to capitalise on entry, for example. Also, an Event can have multiple handlers. Yes and "sender" allows to access the control who raised this event if
needed. -- Show quoteHide quotePatrice <bokit***@ms21.hinet.net> a écrit dans le message de news:1141722802.635698.184700@i39g2000cwa.googlegroups.com... > Hi All, > > I didn't use a "Handles" keyword in VB6. I can't sure its funciton. > > Does it mean that any object behind "handles" keyword will run the same > code? > > ex: > Private Sub A(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles B, C, D, E > > // B , C, D, E objects will get the same message ? > > > END SUB > > > // Thank you very much! > > // BR > // /Boki. > <bokit***@ms21.hinet.net> schrieb:
> I didn't use a "Handles" keyword in VB6. I can't sure its funciton. Yes.> > Does it mean that any object behind "handles" keyword will run the same > code? > > ex: > Private Sub A(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles B, C, D, E > > // B , C, D, E objects will get the same message ? > > > END SUB I suggest to place the caret on 'Handles' and press the F1 key. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> <bokit***@ms21.hinet.net> wrote in message
news:1141722802.635698.184700@i39g2000cwa.googlegroups.com... If anything, it's the other way around.> Does it mean that any object behind "handles" keyword will run the same > code? Your method can handle any of the events that you list in the Handles clause - usually one event per method (but for many objects) as in : Private Sub AnyButton_Click( _ ByVal sender As System.Object _ , ByVal e As System.EventArgs _ ) Handles button1.Click, button2.Click, button3.Click This routine will be called whenever the user clicks on any of button1, button2 or button3. HTH, Phill W. Thank you for example, very clear!
Best regards, Boki. Phill W. wrote: Show quoteHide quote > <bokit***@ms21.hinet.net> wrote in message > news:1141722802.635698.184700@i39g2000cwa.googlegroups.com... > > > Does it mean that any object behind "handles" keyword will run the same > > code? > > If anything, it's the other way around. > Your method can handle any of the events that you list in the Handles > clause - usually one event per method (but for many objects) as in : > > Private Sub AnyButton_Click( _ > ByVal sender As System.Object _ > , ByVal e As System.EventArgs _ > ) Handles button1.Click, button2.Click, button3.Click > > This routine will be called whenever the user clicks on any of > button1, button2 or button3. > > HTH, > Phill W. |
|||||||||||||||||||||||