c# - How to control that dynamically added usercontrol? -


i have code this:

myusercontrol[] mycontrol = new myusercontrol[10]; 

when form load:

for( int = 0; < 10; i++ ) {     mycontrol[i] = new myusercontrol();     mycontrol[i].label1.text = "title";      this.controls.add ( mycontrol[i] ); } 

now show normally.

after press button below:

private void button1_click(object sender, eventargs e) {     mycontrol[0].label1.text = "other title"; } 

when see debug mode,value added normally, lable1 text not show "other title".

so, try below method, not work anything.

mycontrol[0].label1.update(); mycontrol[0].label1.invalidate(); mycontrol[0].label1.refresh(); 

please, kindly advise.

i don't understand concept hope example work you

private void button1_click(object sender, eventargs e) {     //mycontrol[0].label1.text = "other title";      myusercontrol ctrl = null;     foreach (var c in this.controls)     {         if (c.gettype().name == "myusercontrol")         {             var myctrl = (myusercontrol)c;             if (myctrl.text == "title")             {                 ctrl = myctrl;                 break;             }         }     }     if (ctrl != null)     {         ctrl.text = "other title";     } } 

this simple example code work , have enhance like


Comments