110,534
社区成员
发帖
与我相关
我的任务
分享
foreach (TextBox s in this.Controls)
{
MessageBox.Show(s.ToString());
}
遍历 textbox出差错,如下错误:
无法将类型为“System.Windows.Forms.Button”的对象强制转换为类型“System.Windows.Forms.TextBox”。
foreach (var s in this.Controls)
{
if (s.GetType() == typeof(System.Windows.Forms.TextBox))
{
.......
}
}
foreach (Control s in this.Controls)
{
if(s is TextBox )
{
MessageBox.Show((s as TextBox ).Text);
}
}