Accessing controls in a panel -C#

Accessing controls using collection is pretty simple in C#. It comes handy when you want to perform group tasks.

I have a panel which contains many text boxes and Labels. Some of the controls used to format the result. Others name start with txt_ and lbl_. Our task is to clear the Text property with “”/null.


We can iterate through panel controls as follows

foreach(Control c in panel_rateSettings.Controls )
if ( c.Name.Contains(“txt_”) || c.Name.Contains(“lbl_”))

Maybe you can find another use of the control collection.

Published by


A developer,teacher and a blogger obsessed with Python,Dart and open source world from India

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.