Sunday, 15 September 2013

winforms - c# Refresh a child form owned by a parent form -



winforms - c# Refresh a child form owned by a parent form -

i have parentform mainform button start. start calls click event startform_click opens childform, has owned it's parent mainform , modeless, start. on start form have button permissions opens modeless form owned it's parentform start. form permissions has bunch of dynamically created checkboxes. when click button modify button on permissions permissions update checkboxes viewable.

i know when click modify button permissions.txt file beingness updated appropriately. ui dialog not updating reflect right (modified) number of users approved under permissions category. how can forcefulness kid of kid owned it's parent update ui when click button modify on form permissions.

call mainform open childform start

private void startform_click(object sender, eventargs e) { start f1 = new start(); f1.owner = this; f1.show(); }

call start create childform permissions open

private void bpermissions_click(object sender, eventargs e) { permissions af3 = new permissions(); af3.owner = this; af3.show(); widgetlogic.getpermtext(af3); widgetlogic.getdetailerpermtext(af3); widgetlogic.getadminpermtext(af3); }

the various widgetlogic calls update permissions.txt files on server. next think problem is

private void bmodify_click(object sender, eventargs e) { widgetlogic.writeperm(); }

widgetlogic here writing file. i've tried simple this.refresh(); , can't seem phone call start.bpermission_click();. unfortunately because start owns permissions, required when start closes children form must dispose(); fear user certainly muck up.

can point me in right direction please? sincerely appreciate it. give thanks much in advance. :-d

c# gather checkbox.click events later use

your logic in checkchangedperm() not correct. need check if checkbox checked or un-checked:

public static void checkchangedperm(object sender, eventargs e) { checkbox c = sender checkbox; if (c.name != null && c.name != "") { streamreader reader; int count = c.name.count(); string trimmed = c.name.tostring(); string output = trimmed.remove(count - 4); using (reader = new streamreader(datafolder + permfile)) { //here check state of checkbox if(c.checked == false) //add name in permline_ { trimmed = reader.readtoend(); //re-use trimmed string. don't need new 1 if (!trimmed.contains(output)) { trimmed += "\r\n" + output; permline_ = trimmed; } } else //remove name permline_ { permline_ = ""; while ((trimmed = reader.readline()) != null) { if (trimmed != output) { permline_ += trimmed + "\r\n"; } } if (permline_ != "") { permline_ = permline_.remove(permline_.length - 2); //trim lastly \r\n } } //now permline_ contains right string } } }

in writeperm():

streamwriter writer; if(permline_ == "" || permline_ == null){return;} foreach (control c in this.controls) { if (c.gettype() == typeof(system.windows.forms.checkbox)) { if (!permline_.contains(c.name)) { c.visible = false; } } } using (writer = new streamwriter(datafolder + permfile)) { writer.write(permline_); }

finally, in getpermtext() need add together line of code after line = reader.readtoend();

//initialize permline_ string contains of file. permline_ = line;

and check if usercount zero:

... ... usercount = parts.length; if(usercount == 0){return;} checkbox[] chkperm = new checkbox[usercount]; ... ...

edit

it little embarrassing solution way more simple. mean is, need update file whenever press button bmodify. there no need checkchangedperm() function nor alter permline_ string every time checkbox clicked. rewrite bmodify_click():

private void bmodify_click(object sender, eventargs e) { streamwriter writer; string trimmed = "", output = ""; int count; foreach (control c in this.controls) { if (c.gettype() == typeof(checkbox)) { if ( ((checkbox)c).checked == true ) { c.visible = false; } else { count = c.name.count(); trimmed = c.name.tostring(); output += trimmed.remove(count - 4) + "\r\n"; } } } if (output != "") { output = output.remove(output.length - 2); //trim lastly \r\n } using (writer = new streamwriter(datafolder + permfile)) { writer.writeline(output); } }

edit2

you can have writeperm() function in widgetlogic class this:

public static void writeperm(system.windows.forms.form targetform) { streamwriter writer; string trimmed = "", output = ""; int count; foreach (control c in targetform.controls) { if (c.gettype() == typeof(checkbox)) { if ( ((checkbox)c).checked == true ) { c.visible = false; } else { count = c.name.count(); trimmed = c.name.tostring(); output += trimmed.remove(count - 4) + "\r\n"; } } } if (output != "") { output = output.remove(output.length - 2); //trim lastly \r\n } using (writer = new streamwriter(datafolder + permfile)) { writer.writeline(output); } }

and phone call normally:

private void bmodify_click(object sender, eventargs e) { widgetlogic.writeperm(this); }

c# winforms forms button permissions

No comments:

Post a Comment