如何清除表单中的所有文本框的文本? [英] How to clear the text of all textBoxes in the form?
本文介绍了如何清除表单中的所有文本框的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void CleanForm()
{
foreach (var c in this.Controls)
{
if (c is TextBox)
{
((TextBox)c).Text = String.Empty;
}
}
}
这上面的方法不起作用,控件不会被清零。它编译罚款,但什么都不做。
This method above doesn't work and the controls aren't cleared. It compiles fine, but does nothing.
任何想法?
推荐答案
我喜欢拉姆达:)
private void ClearTextBoxes()
{
Action<Control.ControlCollection> func = null;
func = (controls) =>
{
foreach (Control control in controls)
if (control is TextBox)
(control as TextBox).Clear();
else
func(control.Controls);
};
func(Controls);
}
祝你好运!
这篇关于如何清除表单中的所有文本框的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文