This is the article for clearing the textboxes in windows application. This will help to reduce the lines of bunch of code explicitly clear the textbox like
textbox1.text="";
:
:
textbox10.text="";
if we clear the all textbox in the form it will perfect.
public void ClearTextBoxes(Control control)
{
foreach (Control c in control.Controls)
{
if (c is TextBox)
{
((TextBox)c).Clear();
}
if (c.HasChildren)
{
ClearTextBoxes(c);
}
}
}* create the object for the Control class, This holds the reference of all the controls in the form.
* check the control is Textbox
if (c is TextBox)
{
((TextBox)c).Clear();
}* Some times we need situation null the textbox values in nested controls like Tabcontrol etc, That situation we need to check the other textboxes in the nested control(Tabcontrol).
if (c.HasChildren)
{
ClearTextBoxes(c);
}It will find the children of the form and check that have a textbox. Its a recursive function. Next time this function pass the reference of the child control.
