c# - Dynamically looping through controls has no effect -


i have gui class. pass frmmain (form) gui contructor. have following method access child controls:

public void assignevents(frmmain frm) {     foreach (control ctl in frm.controls)     {         ctl.backcolor = color.greenyellow;         log.adddata(ctl.name.tostring() + ".backcolor = " + ctl.backcolor.tostring(), 3);     } } 

i new updated color in output (log), takes no effect on controls , still in default color. ideas i'm doing wrong?

edit:

i call this:

    // gui.cs     public class gui {          public gui(frmmain frm){              assignevents(frm);          }     }      // frmmain.cs     public frmmain()     {         initializecomponent();         gui  = new m.gui (this);     } 

based on comment, need try go recursively through each controlcollection set backcolor property.

try changing code this:

public gui(frmmain frm) {   assignevents(frm.controls); }  public void assignevents(control.controlcollection controls) {   foreach (control ctl in controls) {     ctl.backcolor = color.greenyellow;     assignevents(ctl.controls);   } } 

Comments

  1. Thank you for a useful blog and tips for developers. I need to promote my app and for my project, the information from your blog is simply irreplaceable! I have long been looking for a similar resource to simplify my life and finally found. I am very grateful to you.

    ReplyDelete

Post a Comment

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -