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); } }
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