使用C#编程遍历页面上所有TextBox控件并给它赋值为string.Empty
// 引入命名空间
using System.Windows.Forms;
// 遍历页面上所有TextBox控件并赋值为空字符串
private void ClearTextBoxes(Control control)
{
foreach (Control c in control.Controls)
{
if (c is TextBox)
{
((TextBox)c).Text = string.Empty;
}
else if (c.HasChildren)
{
ClearTextBoxes(c);
}
}
}
// 调用方法
ClearTextBoxes(this);