c# - How to change the property of a control from a flowlayoutpanel? -


how change property of control in flowlayoutpanel assuming add controls programatically , assuming name of each controls same?

for example image shows there 2 text boxes , 2 buttons, how change color of button 2? assuming controls has been added @ runtime.

alt text

foreach(controls ctrl in flowlayoutpanel1.controls) { //what should put here? } 

well, easiest way retain explicit reference buttons you're adding. otherwise add tag distinguish them (to robust against i18n issues). e.g. can set tag of "button2" "button2" , can use:

foreach (control ctl in flp.controls) {     if ("button2".equals(ctl.tag)) {         ctl.backcolor = color.red;     } 

}

i assuming problem find actual button again , not setting background color. likewise check control being button , text being "button2" if text can change depending on ui language that's not idea.

eta: totally forgot can use control's name property well.

if want change background color of button in response event button can use sender argument of event handler, though.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -