c# - How to delete all textarea in form? -
i tried method:
private void cleartextboxes() { action<control.controlcollection> func = null; func = (controls) => { foreach (control control in controls) if (control textbox) (control textbox).dispose(); else func(control.controls); }; func(controls); }
it not work, if refresh form.
if want delete textarea form should remove parent controls collection , call dispose on objects implement idisposable when have finished them, unmanaged resources own released. if not call dispose() on not needed textbox cleaned when gc decides , happen in middle of application run or in end. difference here if call dispose() explicitly object finalization performed on next run of gc otherwise in first run gc put object finalization queue , clean memory on run.
private void cleartextboxes() { action<control.controlcollection> func = null; func = (controls) => { foreach (control control in controls) if (control textbox) { controls.remove(control); } else func(control.controls); //here after removing controls should call dispose clean-up }; func(controls); }
if want celar textboxes area should call clear method.
private void cleartextboxes() { action<control.controlcollection> func = null; func = (controls) => { foreach (control control in controls) if (control textbox) (control textbox).clear(); else func(control.controls); }; func(controls); }
Comments
Post a Comment