The DirectCast statement simply converts the "sender" variable (which is
declared as an Object) to a Button. Essentially, if you click on Button1 you
get Button1 passed to the Click event handler as an object. Cast it back to
a Button and you can do anything you want with it including accessing it's
properties such as name, text, position, etc....
See this discussion for some more information. It's a very similar
problem... at least the part about adding multiple buttons...
http://www.devcity.net/forums/topic.asp?tid=4087&page=2
"Paul Mars" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Cor, thanks for your help.
>
> In my program the number of buttons created is not a constant, so your
> paragraph 3 would not work, right? I am still lost in space. Note that in
my
> code clicking any button created does trigger the Addhandler delegate
> "GameBtns", but this delegate thinks all buttons created have the same
name.
> Maybe this is where the Sender Object come in, but I have not gotten a
full
> understanding of this yet. I did look up "DirectCast keyword" in help and
I
> do not understand what it says, sorry. I previously tried looking up how
to
> respond to events triggered by objects created during run time in help,
but
> found nothing. Maybe I did not use the right search word(s).
>
> I did try If DirectCast(Sender, Button).Name = blablabla, but what do I
use
> for the name?
>
> Paul
>
> PS: I just had a thought, well many thoughts, but this one might not
> embarrass me. Can I do like u say in paragraph 3 and then use code to add
> the button names to the event handle?? Maybe that is what u meant.
>
>
> "Cor" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hi Paul,
> >
> > Nice that you wrote you are a student, than we can take the students
> > approach and that is helping and not give code.
> >
> > You can add to every control the same handler. So when you create it,
you
> > can add all the time the same event code to the control. Important is
that
> > when you add an handler for an event that is has the right signature
from
> > that event.
> >
> > What I sometimes do (when I have a lot of the same controls) is just
> create
> > one event from the IDE, delete the event handler at the end, give the
> event
> > another name and than add that to all my controls which needed that
event.
> >
> > In the event we can than see which did throw it by using the sender
> object.
> > For that I give you some code, because you have to tell what kind of
> control
> > it was (or that it was a control).
> >
> > This can be something as
> >
> > If directcast(sender,control).name = blablabla
> > or
> > If directcast(sender,checkbox).checked = true
> >
> > I hope that this gives you some ideas?
> >
> > Cor
> >
> >
>
>