c# - Readonly properties -
hi here try make method can loop on form , convert text boxenter image description here read only=true read = false not working
public static void unread only(form frm) { foreach (control item in frm.controls) { if (item textbox) { // item.readonly = false; } } }
primarily problem not casting control textbox
have access property want set.
foreach (control item in frm.controls) { if (item textbox) { var textbox = item textbox; textbox.readonly = false; } }
that said, controls can contain child control, need crawl entire form looking embedded text boxes.
this check form , controls text boxes , set them read only
public static void setreadonly(control frm) { var controls = new queue<control>(); controls.enqueue(frm); while (controls.count > 0) { var control = controls.dequeue(); if (control textbox) { var txtbox = control textbox; txtbox.readonly = true; } if (control.haschildren) { foreach (var child in control.controls.oftype<control>()) { controls.enqueue(child); } } } }
the code pretty self explanatory should walk through flow understand doing.
Comments
Post a Comment