Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have panel array in C#.I want to know how can I catch the panel when its doubleclick event is used.I mean that panel is which panel of the panel array without effecting other panels in panel array because I want to set the double clicked panel's color.
Posted

1 solution

Your question is a little unclear but i would bind to the double click event for each panel and use the sender paramater of the event to identify the panel clicked. This assumes win forms, WPF is a whole other thing and routed events can be used on the parent container.

C#
public void InitializeComponent()
{
    Panel[] panels = new Panel[] { new Panel(), new Panel() };
    foreach (Panel panel in panels)
    {
        panel.DoubleClick += new EventHandler(panel_DoubleClick);
    }
}

private void panel_DoubleClick(object sender, EventArgs e)
{
    ((Panel) sender).BackColor = Color.Red;
}
 
Share this answer
 
Comments
Htike Htike Aung 9-Nov-10 1:28am    
Thanks David.Your instruction works well for my coding.

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