winforms - C# Hide all labels/ controls -
is possible within windows form using c# hide specific controls upon form load, e.g. labels or buttons , chose show ones wan't shown?
i've got program contains lot of buttons , labels want 1 or 2 shown upon load , feel doing method of label1.hide();
every label seems inefficient instead show labels want when want. maybe using loop, this:
foreach (label) { this.hide(); }
it sounds hide them in designer, , wouldn't have deal hiding them @ runtime.
if have hide them @ runtime, can grab controls on form of type little linq:
foreach (var lbl in controls.oftype<label>()) lbl.hide();
you filter controls based on name, hide ones want hide:
foreach (var lbl in controls.oftype<label>().where(x => x.name != "lblalwaysshow")) lbl.hide();
if they're tucked inside of other controls, panels or groupboxes, you'll have iterate through controlcollections too:
foreach (var lbl in panel1.controls.oftype<label>()) lbl.hide(); foreach (var lbl in groupbox1.controls.oftype<label>()) lbl.hide();
Comments
Post a Comment