473,511 Members | 15,624 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Event Handlers in Arrays

Hi,
I am creating an array of PictureBoxes on my Windows Form.

PictureBox temp;
PictureBox[10,10] myArea = new Picture
for (int x=0; x<10; x++)
{
for (int y=0; y<10; y++)
{
temp = new PictureBox();
temp.Location = new Point(1+(x*MAX), 1+(y*MAX));
temp.Size = new Size(MAX, MAX);
temp.BackColor = System.Drawing.Color.Green;

myArea[x, y] = temp;
myArea[x, y].Click +=new EventHandler(my_Click);
this.Controls.Add(temp);
}
}
private void my_Click(object sender, EventArgs e)
{
// now here I need to get the PictureBox which was clicked and do
some operations on it.

}
Can someone tell me how to get which picturebox was clicked?

Thanks in Advance for your help
Nov 17 '05 #1
1 1246
if the eventhandler is invoked, the picturebox that was clicked is passed as
the "sender"-parameter, you just cast it back to PictureBox if necessary.

"Xarky" <be*********@yahoo.com> schrieb im Newsbeitrag
news:bc************************@posting.google.com ...
Hi,
I am creating an array of PictureBoxes on my Windows Form.

PictureBox temp;
PictureBox[10,10] myArea = new Picture
for (int x=0; x<10; x++)
{
for (int y=0; y<10; y++)
{
temp = new PictureBox();
temp.Location = new Point(1+(x*MAX), 1+(y*MAX));
temp.Size = new Size(MAX, MAX);
temp.BackColor = System.Drawing.Color.Green;

myArea[x, y] = temp;
myArea[x, y].Click +=new EventHandler(my_Click);
this.Controls.Add(temp);
}
}
private void my_Click(object sender, EventArgs e)
{
// now here I need to get the PictureBox which was clicked and do
some operations on it.

}
Can someone tell me how to get which picturebox was clicked?

Thanks in Advance for your help

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
3562
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
8
3116
by: Dennis C. Drumm | last post by:
I have a class derived from a SortedList called SystemList that contains a list of objects indexed with a string value. The definition of the objects contained in the SortedList have a boolean...
18
4807
by: bhavin | last post by:
Hi, Can someone point me to some good best practices kind of documentation on use of events compared to method overriding. Ex. In Windows Forms when should i have an event handler for Paint, and...
13
3479
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
5
3848
by: Amit | last post by:
Hello! Is it possible to find how many event handlers an event has at runtime? How about finding whether or not an event has event handlers? In C# you can compare the event with null to check if...
7
1698
by: Michael D. Ober | last post by:
Is there anyway to raise an event from a class and require that any program using that class (not just inheritance) have an event handler for specific events in the class? In my case, some events...
6
28100
by: Kevin Attard | last post by:
I am using a GridView inside a UserControl which has a template column for deleting the rows. Before databinding the gridview i am attaching the RowCommand and RowDataBound event. I am using the...
16
2481
by: Hamed | last post by:
Hello I am developing a utility to be reused in other programs. It I have an object of type Control (a TextBox, ComboBox, etc.) that other programmers use it in applications. they may set some...
14
8572
by: Hamed | last post by:
Hello It seems that I should implement ICloneable to implement my own clone object. the critical point for me is to make a control object based on another control object that all of its event...
6
2000
by: Tony Johansson | last post by:
Hello! I know it's possible to have several event handler for a single event but I can't see any point using several event handler for this. I'm probably wrong so can anybody tell me what...
0
7252
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7371
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5676
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.