表单中的 Foreach 控件,如何对表单中的所有文本框执行操作? [英] Foreach Control in form, how can I do something to all the TextBoxes in my Form?

查看:22
本文介绍了表单中的 Foreach 控件,如何对表单中的所有文本框执行操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Foreach 语句对我的文本框执行某些操作?

How can I use a Foreach Statement to do something to my TextBoxes?

foreach (Control X in this.Controls)
{
    Check if the controls is a TextBox, if it is delete it's .Text letters.
}

推荐答案

您正在寻找

foreach (Control x in this.Controls)
{
  if (x is TextBox)
  {
    ((TextBox)x).Text = String.Empty;
  }
}

这篇关于表单中的 Foreach 控件,如何对表单中的所有文本框执行操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆