Click here to Skip to main content
15,906,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am created the panels at run time. Add'd those panels at already created panel using
Panel1.controls.Add(p1[i]);
I created a n number of panels at run time and added those add panel1. When i click the panel created at run time i need a value of i. or Need to know name of panel. If know means please help me.
Posted

You can add the click event handler to the panel:

C#
p1[i].Click += DynamicPanels_Click;


The click event would look like this:

C#
private void DynamicPanels_Click(object sender, EventArgs e)
{
    (sender as Panel).Name;   // get the name
}
 
Share this answer
 
Comments
ssyuvaraja 23-Aug-11 7:46am    
Thank you. (sender as Panel).Name; this is working.
You will need to define a name to the panel yourself - since these are dynamic panels.
You can do this when you are creating them - via the Name property.
 
Share this answer
 
You can put i in the Tag property. Or you can set the Name property as the other two solutions mention.

What is generally better is to store a reference to the panels (in a List<Panel> or similar) and look them up in there, instead of relying on numbers. Or if the reason you want the number is to look something up in another data structure, store a reference to the target object in Tag.
 
Share this answer
 

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