Click here to Skip to main content
15,894,720 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In a class, I have an array of panels which each contains the same picturebox.

SQL
public Panel[] NumberPanel;
public PictureBox AddBox;
NumberPanel.Controls.Add(ABCBox);

AddBox.Click += new System.EventHandler(AddBox_Click);


When creating an object it creates the panel and the picture in it.

How can I know the index of the panel when clicked on one of the pictures in one of the panels.

private void AddBox_Click(object sender, EventArgs e)
{
int index;
index=???;
}
Posted
Updated 23-Dec-12 7:26am
v6

1 solution

I dont think that there is any direct method since its you defines the class structure you need to keep the index of the panel as a member to the insider control.

I believe you have used a custom control to create your object which holds panel and picturebox.

One thing you can do is expose custom event which simulates that picbox inside the panel(customcontrol) is clicked by keeping the index as a property to the custom control or class which holds the panel/picture box.
 
Share this answer
 
Comments
missak boyajian 23-Dec-12 14:46pm    
When i create the object q1[0]= new drawing(X,y); it draws the panel at specific x y position. But when the user clicks on the picture i need to know which one is clicked like q1[?]. Picture. I didnt understand your explanation.
Jibesh 23-Dec-12 14:51pm    
how the panel and picture are related? are they clubbed to one control?

The idea is like you know the index when you are creating the panel/image i mean q1[0] here '0' means the index. store this information also into the drawing class.

can you add more details about your code to understand more and to have a better solution for this. You can use the 'Improve Question' button to update your question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900