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.

2018-01-05_220714

We can iterate through panel controls as follows

foreach(Control c in panel_rateSettings.Controls )
{
if ( c.Name.Contains(“txt_”) || c.Name.Contains(“lbl_”))
{
c.Text=null;
}
}

Maybe you can find another use of the control collection.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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.