C# Change properties of control added at runtime to winform -


i need add variable number of progress bars form , update them required. can add progress bars fine, cannot find way update properties.

int pbcount = 0; void addprogressbar(int, pbx, int pby, int initalvalue)  {     pbcount++;     progressbar mybar = new progressbar();     mybar.name = "mybar" + pbcount.tostring();     mybar.location = new system.drawing.point(pbx, pby);     mybar.width = 200;     mybar.height = 20;     mybar.minimum = 0;     mybar.maximum = 100;     mybar.value = initialvalue;     this.controls.add(mybar); } 

so how change value of given progress bar?

or there better way of adding progress bars updating later?

try this:

progressbar bar7 = this.controls.oftype<progressbar>().firstordefault( x => x.name == "mybar7" ); 

if doesn't find "mybar7" return null.

then can update properties needed.

another option store progress bars in dictionary< string, progressbar >;

here example using linqpad:

it shows how add new progressbar dictionary, , how dictionary.

you use simple array if want access progressbars index.

dictionary<string,progressbar> progressbars = new dictionary<string,progressbar>();  void main() {     progressbars["mybar1"] = new progressbar();      //... later on     progressbar progressbar = progressbars["mybar1"];     progressbar.performstep();     progressbar.step = 77;      progressbar.step.dump();  } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -