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

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -