Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to reduce that code. I create a list of the panels.
And apply ElipseControl() to buttons in that panels in one loop.

What I have tried:

private new void Show()
       {
           PanCla.Enabled = true;
           PanCla.Visible = true;
           PanMd1.Visible = false;
           PanMd2.Visible = false;
           PanelAdm.Visible = false;

           List<Panel> panels = new List<Panel>();  // here my list
           panels.Add(PanCla);
           panels.Add(PanMd1);
           panels.Add(PanMd2);
           panels.Add(PanelAdm);

           // i tryed this but not working to combining

           //foreach (Control p in panels.Controls)
           //{
           //    if (p is Button)   // I need to talk to buton in list of panels.
           //    {
           //        var eli = new ElipseControl();
           //        eli.TargetControl = p;
           //        eli.CornerRadius = 20;
           //    }
           //}


           foreach (Control c in PanCla.Controls)
           {
               if (c is Button)
               {
                   var el = new ElipseControl {TargetControl = c, CornerRadius = 20};
               }
           }

           foreach (Control c in PanMd1.Controls)
           {
               if (c is Button)
               {
                   var el = new ElipseControl {TargetControl = c, CornerRadius = 20};
               }
           }

           foreach (Control c in PanMd2.Controls)
           {
               if (c is Button)
               {
                   var el = new ElipseControl {TargetControl = c, CornerRadius = 20};
               }
           }

           foreach (Control c in PanelAdm.Controls)
           {
               if (c is Button)
               {
                   var el = new ElipseControl {TargetControl = c, CornerRadius = 20};
               }
           }

           ElipseControl els = new ElipseControl();
           els.TargetControl = this;
           els.CornerRadius = 20;
           els.TargetControl = label5;
           els.CornerRadius = 20;
       }


excuse my bad english.
Posted
Updated 11-Jun-21 5:16am
Comments
SeeSharp2 11-Jun-21 11:10am    
I do not understand your question.
[no name] 11-Jun-21 11:17am    
You could create a common routine (with a collection parameter) for the for loop; however, "var el" is going into the bit bucket.
Richard Deeming 11-Jun-21 11:52am    
REPOST
This is the same question you posted on Wednesday:
I need to loop in buttons[^]
Richard MacCutchan 12-Jun-21 4:23am    
Sorry, I missed the original.

1 solution

Would this do it:
C#
foreach (Panel panel in panels)
{
    foreach (Control c in panel.Controls)
    {
        if (c is Button)
        {
           var el = new ElipseControl {TargetControl = c, CornerRadius = 20};
// But you need to do something with the el variable I think.
        }
    }
}
 
Share this answer
 
Comments
GSylvain55 11-Jun-21 11:44am    
Yes, cool, it's work perfecly !!! :)
Richard MacCutchan 11-Jun-21 11:59am    
You're welcome.

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