471,605 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,605 software developers and data experts.

passing data with an eventhandler

At runtime I generate 8 pictureboxes, when the user click on a picturebox I
fire an onclick eventhandler. Because these pictureboxes are generate at
runtime I do not have direct access to the their name property.

I need to know the name of the picturebox that the user click on so my
question is,
is it possible to pass data with en evenhandler like onclick? or is there a
another approach to
this that I am missing?
--
________________________
Gunnar Gudmundsson
Dec 28 '05 #1
7 3309
OfurG?rn <of******@nospam.nospam> wrote:
At runtime I generate 8 pictureboxes, when the user click on a picturebox I
fire an onclick eventhandler. Because these pictureboxes are generate at
runtime I do not have direct access to the their name property.

I need to know the name of the picturebox that the user click on so my
question is,
is it possible to pass data with en evenhandler like onclick? or is there a
another approach to
this that I am missing?


Why not pass the picturebox as the "source" argument of the event
handler?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 28 '05 #2
Hi,

"OfurGřrn" <of******@nospam.nospam> wrote in message
news:91**********************************@microsof t.com...
At runtime I generate 8 pictureboxes, when the user click on a picturebox
I
fire an onclick eventhandler.
Correctely speaking you handle the Click event that the picturebox fires
when he receive a click, you do not fire nothing, you receive it.
Because these pictureboxes are generate at
runtime I do not have direct access to the their name property.
You will have the same situation if the same handler (or the same method)
handles more than one event or the same event fired by more than one
control.
I need to know the name of the picturebox that the user click on so my
question is,
is it possible to pass data with en evenhandler like onclick? or is there
a
another approach to
this that I am missing?


The first parameter of EventHandler gives you who sent it, IF you know for
sure that only a PictureBox instance will fire it you can cast the sender
parameter to PictureBox.
If you are not sure you can cast it to a Control

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Dec 28 '05 #3
As a follow up to Jon and Ignacio's posts, you can set a name property on a
dynamically generated control when it is created. When the event is fired,
you can get this property out of the

((PictureBox)sender).Name;

in your eventhandler code.

--Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"OfurGørn" wrote:
At runtime I generate 8 pictureboxes, when the user click on a picturebox I
fire an onclick eventhandler. Because these pictureboxes are generate at
runtime I do not have direct access to the their name property.

I need to know the name of the picturebox that the user click on so my
question is,
is it possible to pass data with en evenhandler like onclick? or is there a
another approach to
this that I am missing?
--
________________________
Gunnar Gudmundsson

Dec 28 '05 #4
"OfurGřrn" <of******@nospam.nospam> a écrit dans le message de news:
91**********************************@microsoft.com...

| At runtime I generate 8 pictureboxes, when the user click on a picturebox
I
| fire an onclick eventhandler. Because these pictureboxes are generate at
| runtime I do not have direct access to the their name property.
|
| I need to know the name of the picturebox that the user click on so my
| question is,
| is it possible to pass data with en evenhandler like onclick? or is there
a
| another approach to
| this that I am missing?

The sender parameter to the event handler *is* the component that triggers
the event.

Simply cast the sender to Control and then you can access the Name property.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Dec 28 '05 #5
I was afraid it was something simple.
Thank you

--
________________________
Gunnar Gudmundsson
"Joanna Carter [TeamB]" wrote:
"OfurGørn" <of******@nospam.nospam> a écrit dans le message de news:
91**********************************@microsoft.com...

| At runtime I generate 8 pictureboxes, when the user click on a picturebox
I
| fire an onclick eventhandler. Because these pictureboxes are generate at
| runtime I do not have direct access to the their name property.
|
| I need to know the name of the picturebox that the user click on so my
| question is,
| is it possible to pass data with en evenhandler like onclick? or is there
a
| another approach to
| this that I am missing?

The sender parameter to the event handler *is* the component that triggers
the event.

Simply cast the sender to Control and then you can access the Name property.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer

Dec 28 '05 #6
OfurG?rn <of******@nospam.nospam> wrote:
I was afraid it was something simple.


Never be afraid that the solution will be simple. Be hopeful that it'll
be simple, and afraid that it will be complicated :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 29 '05 #7
Hi ,

I just wanted to check how things are going. If there is any question,
please feel free to join the community and we are here to support you at
your convenience. Thanks again and Happy New Year!

Best Regards,

Terry Fei [MSFT]
Microsoft Community Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Dec 30 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by gkr | last post: by
8 posts views Thread by Bishoy George | last post: by
3 posts views Thread by OG | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by MichaelMortimer | last post: by
reply views Thread by CCCYYYY | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.