Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
In a class, I have an array of panels which each contains the same picturebox.
 
 
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 23-Dec-12 7:51am
Edited 23-Dec-12 8:26am
v6

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
missak boyajian at 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 at 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)

  Print Answers RSS
0 OriginalGriff 375
1 Sergey Alexandrovich Kryukov 329
2 CPallini 260
3 DamithSL 214
4 Maciej Los 197
0 OriginalGriff 5,455
1 DamithSL 4,457
2 Maciej Los 3,885
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,115


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 23 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100