c# - Show progress in dynamically generated progress bar in Windows application -


i have few progress bars created in run time on button click.

private void button1_click(object sender, eventargs e) {     int count=0;      for(var item in items)     {         count++;         progressbar pbar = new progressbar();         pbar.name = "progressbar1_"+count;         pbar.width = 200;         pbar.height = 15;         pbar.minimum = 1;         pbar.maximum = 100;         pbar.value = 1;         panel1.controls.add(pbar); 

how access dynamically created progress bar show progress?

"progressbar1_"+count.performstep();// doesnt work  

in loop every time call

progressbar pbar = new progressbar(); 

you create new instance of progress bar.

one option remember instance in list or dictionary.

something that:

list<string> items = new list<string>() { "item" };  dictionary<string, progressbar> progressbars = new dictionary<string, progressbar>();  private void button1_click(object sender, eventargs e) {     int count=0;      foreach(var item in items)     {         count++;         progressbar pbar = new progressbar();         pbar.name = "progressbar_" + count;         pbar.width = 200;         pbar.height = 15;         pbar.minimum = 1;         pbar.maximum = 100;         pbar.value = 1;         panel1.controls.add(pbar);          progressbars.add(pbar.name, pbar);     } }  private void button2_click(object sender, eventargs e) {     progressbars["progressbar_1"].performstep(); } 

the second option search instance in controls of panel.

list<string> items = new list<string>() { "item" };  private void button1_click(object sender, eventargs e) {     int count=0;      foreach(var item in items)     {         count++;         progressbar pbar = new progressbar();         pbar.name = "progressbar_" + count;         pbar.width = 200;         pbar.height = 15;         pbar.minimum = 1;         pbar.maximum = 100;         pbar.value = 1;         panel1.controls.add(pbar);          progressbars.add(pbar.name, pbar);     } }  private void button3_click(object sender, eventargs e) {     (panel1.controls.find("progressbar_1", false).single() progressbar).performstep(); } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -