c# - How can I chang the text of all controls on form from another form -
i have 2 form (form1,form2) code on form2 ... create loop of controls on form1 , name of command (controlname) want send text (ex."sherif") command (case button)
foreach (control ctrl in form1.controls) { form1.controls[controlname]).text = "sherif"; }
error message appears nullreferenceexception object reference not set instance of object. if pointer stop above [controlname] read name of control, when go on comes null value
if want alter text
properties of controls in form, should it:
foreach (control ctrl in form1.controls) { ctrl.text = "sherif"; }
note alter controls in top level , not nested controls....
if need nested controls too, recursively:
public void recursivechange(control control) { foreach (control ctrl in control.controls) { recursivechange(ctrl); ctrl.text = "sherif"; } }
c# winforms
No comments:
Post a Comment