My code:
private void clearToolStripMenuItem_Click(object sender, EventArgs e)
{
RecursiveClearTextBoxes(this.Controls);
}
private void RecursiveClearTextBoxes(Control.ControlCollection cc)
{
foreach (Control ctrl in cc)
{
TextBox tb = ctrl as TextBox;
if (tb != null)
tb.Clear();
else
RecursiveClearTextBoxes(ctrl.Controls);
}
}
{
RecursiveClearTextBoxes(this.Controls);
}
private void RecursiveClearTextBoxes(Control.ControlCollection cc)
{
foreach (Control ctrl in cc)
{
TextBox tb = ctrl as TextBox;
if (tb != null)
tb.Clear();
else
RecursiveClearTextBoxes(ctrl.Controls);
}
}

VulpesPosted Jun 30, 2014, 5:34 AM
Joe WilsonPosted Jul 4, 2014, 4:22 AM
VulpesPosted Jul 2, 2014, 7:26 PM
Check out this SO thread:
http://stackoverflow.com/questions/4710145/how-can-i-get-scrollbars-on-picturebox
Joe WilsonPosted Jun 30, 2014, 3:14 PM
VulpesPosted Jun 30, 2014, 1:33 PM
My own effort deals with this by checking the HasChildren property is true before calling the method.
Joe WilsonPosted Jun 30, 2014, 7:58 AM
I understood that my code was correct too,although I was thinking that it is not wrong.
Khan Abrar AhmedPosted Jun 30, 2014, 5:28 AM
some time text box clear is having a issue, instead of this you can use the Textbox.Text = string.empty;
private void clearToolStripMenuItem_Click(object sender, EventArgs e)
{
RecursiveClearTextBoxes(this.Controls);
}
private void RecursiveClearTextBoxes(Control.ControlCollection cc)
{
foreach (Control ctrl in cc)
{
TextBox tb = ctrl as TextBox;
if (tb != null)
{
tb.Text= string.empty;
}
else
{
RecursiveClearTextBoxes(ctrl.Controls);
}
}
}