473,218 Members | 1,322 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,218 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 3366
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: spammy | last post by:
Hi all, Im attempting to use a COM class in C# via .NET interop. The class has two modes - synhrounous and asynchronous. The mode is determined by the use (or not) of an optional out parameter:...
11
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
8
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
0
by: adam | last post by:
i have custom user control and i'm trying to pass values to custom user control......I need help it seems to me i cannot pass the value to user control from dropdownlist. I have property in a...
4
by: gkr | last post by:
Hi I would like to pass values/data from Page1 to Page 2, then capture values on page 2 and return back to Page 1 with the values from page2. Can you pls guide me on how to do this ? I tried...
8
by: Bishoy George | last post by:
how to let javascript code understand txtUser.Text? in window.open("WebForm26.aspx?User=txtUser.Text",.....................)
7
by: AMP | last post by:
Hello, I have this in form1: namespace Pass { public partial class Form1 : Form { public Form2 form2; public Form1() {
1
by: mfunkmann | last post by:
Hi, I recently got an error and I don't know how to fix it: Error 1 'System.Data.DataColumn' does not contain a definition for 'Windows' C:\c#\CsharpPRO\Form1.Designer.cs 304 77 CsharpPRO I...
3
by: OG | last post by:
I'm trying to learn C# 2008 on Microsoft's MSDN. Their walkthrough example on passing data between forms at http://msdn.microsoft.com/en-us/library/ms171925.aspx had this error in the C# version...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.