首先,要想遍历,就必须找到你想找的表单里面的所有控件,然后一个个的逐一比对,当找到了你需要的控件的时候,再做你需要的操作。

1、foreach方法

foreach (Control control in 表单信息.Controls)
{
if (control is 控件类型)
{
控件类型t = (控件类型)control;
//逻辑代码
}
}

示例:

foreach (Control control in this.Controls)
{
if (control is TextBox)
{
TextBox t = (TextBox)control;
if (t.Text == "")
{
//......
}
}
}





相关文章:

  • 2022-12-23
  • 2022-01-03
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
  • 2021-07-19
  • 2021-09-11
  • 2022-12-23
猜你喜欢
  • 2021-08-16
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
相关资源
相似解决方案