textBox的小问题

king4th0 2003-12-05 04:50:59
for循环怎么写?
我想让好几个textBox的text都清空,怎么写?
for(int i=0;i<10;i++)
{
?????//texti.text = "" 怎么表示}
...全文
74 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
gzhubonet 2003-12-06
  • 打赏
  • 举报
回复
相信你已经有了答案了。。

我就祝你成功!!!!!!!!!
Alpha001 2003-12-06
  • 打赏
  • 举报
回复
楼上各位的foreach(Control c in this.Controls)方法应该可行,

但如果该Form中的控件较多,执行效率可能稍低(需要遍历查找),

如果你已经知道自己需要几个TextBox控件了,不妨将它们放入

一个System.Windows.Forms.TextBox数组中,然后对该数组用

for(……)或foreach(……)遍历并使之Text=""即可。
Hexudong1979 2003-12-06
  • 打赏
  • 举报
回复
我想yanransoft()说的方法是可行的,以前我也这么用的
seztty 2003-12-06
  • 打赏
  • 举报
回复
good method
king4th0 2003-12-06
  • 打赏
  • 举报
回复
i'm sorry i don't
LiSDN 2003-12-06
  • 打赏
  • 举报
回复
do you have other way?
king4th0 2003-12-06
  • 打赏
  • 举报
回复
foreach(Control c in this.Controls)
{
if(c.GetType().ToString()=="System.Windows.Forms.TextBox")
c.Text="";

}
这样会不会显得很罗索?
king4th0 2003-12-06
  • 打赏
  • 举报
回复
good,thank you!
simanh 2003-12-05
  • 打赏
  • 举报
回复
楼上诸位都说了,用foreach,很好用的(对于IEnumerator类的东西)
yanransoft 2003-12-05
  • 打赏
  • 举报
回复
foreach(Control c in this.Controls)
{
if(c.GetType().ToString()=="System.Windows.Forms.TextBox")
c.Text="";

}
sjzwinfor 2003-12-05
  • 打赏
  • 举报
回复
将所有的textbox控件放在一个panel中
foreach(TextBox txt in this.panel1.Controls)
{
txt.Text="";
}
sjzwinfor 2003-12-05
  • 打赏
  • 举报
回复
二楼的不能用呀,报错,?
CSCM 2003-12-05
  • 打赏
  • 举报
回复
foreach还可以这么用,呵呵,学习
亚非 2003-12-05
  • 打赏
  • 举报
回复
FileNewExit((呵呵)) 的可用,不错不错!!!
polarlm 2003-12-05
  • 打赏
  • 举报
回复
还是觉得二楼的好
king4th0 2003-12-05
  • 打赏
  • 举报
回复
C#中没有for()了吗?
总是觉得control什么的不怎么好理解
openhouse 2003-12-05
  • 打赏
  • 举报
回复
string mytext="";
foreach(Control ct in this.Controls)
{
if(mytext=="System.Windows.Forms.TextBox")
{
((TextBox)ct).Text="";
}
}
手写的没有调试过,不过就是这个思路,你试试看吧!
FileNewExit 2003-12-05
  • 打赏
  • 举报
回复
foreach(Control c in this.Controls)
{
TextBox tb = c as TextBox;
if(tb != null)
tb.Text = "";
}
king4th0 2003-12-05
  • 打赏
  • 举报
回复
是TextBox吧!
没有效果,没有清空
LiSDN 2003-12-05
  • 打赏
  • 举报
回复
foreach(TectBox txt in this.Controls)
{
txt.Text="";
}

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧