Home All Groups Group Topic Archive Search About
Author
7 Mar 2006 9:13 AM
bokiteam
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.

Author
7 Mar 2006 9:23 AM
Paul Robson
bokit***@ms21.hinet.net wrote:
Show quoteHide quote
> 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
>

B,C,D and E are Events of an object declared withevents

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.
Author
7 Mar 2006 9:24 AM
Patrice
Yes and "sender" allows to access the control who raised this event if
needed.
--
Patrice

<bokit***@ms21.hinet.net> a écrit dans le message de
Show quoteHide quote
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.
>
Author
7 Mar 2006 9:36 AM
Herfried K. Wagner [MVP]
<bokit***@ms21.hinet.net> schrieb:
> 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

Yes.

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/>
Author
7 Mar 2006 12:22 PM
Phill W.
<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.
Author
7 Mar 2006 3:41 PM
bokiteam
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.