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);
}
}


VulpesRank #55 · 29.2K reputationPosted Jun 30, 2014, 1:34 AM EDT
Khan Abrar AhmedRank #778 · 3K reputationPosted Jun 30, 2014, 1:28 AM EDT
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);
}
}
}
Joe WilsonRank #631 · 3.8K reputationPosted Jun 30, 2014, 3:58 AM EDT
I understood that my code was correct too,although I was thinking that it is not wrong.
VulpesRank #55 · 29.2K reputationPosted Jun 30, 2014, 9:33 AM EDT
My own effort deals with this by checking the HasChildren property is true before calling the method.
Joe WilsonRank #631 · 3.8K reputationPosted Jun 30, 2014, 11:14 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 2, 2014, 3:26 PM EDT
Check out this SO thread:
http://stackoverflow.com/questions/4710145/how-can-i-get-scrollbars-on-picturebox
Joe WilsonRank #631 · 3.8K reputationPosted Jul 4, 2014, 12:22 AM EDT