在C#中的表单应用程序中找到文本框 [英] find textbox in form application in c#

查看:93
本文介绍了在C#中的表单应用程序中找到文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以一般功能(如
)的形式找到文本框 和文本框,如
txtbarcode1
txtbarcode2
txtbarcode3
txtbarcode4
txtbarcode5
txtbarcode6

I want to find textbox in form in general function like
and textbox like
txtbarcode1
txtbarcode2
txtbarcode3
txtbarcode4
txtbarcode5
txtbarcode6

private void lookControl()
{
      for(int i=1;1<=12;i++)

           {

                //// find control here with ("txtbarcode"+i) //// 

           }
} 



如果有的话请给我发代码


谢谢
Mohit



if anyway plz send me code


thanks you
Mohit

推荐答案

有一个代码:

There is a code:

public void LookControl()
{
    foreach (Control control in this.Controls)
    {
        if (control is TextBox)
            // You can check any other property here and do what you want
            // for example:
            if ((control as TextBox).Text == string.Empty)
                ;//Action
    }
}



让我知道您是否还有其他想法.



Let me know if there is something else in your mind.


应该是工作人员
it should be Work guys
 public void LookControl()
       {
for (int i = 1; i <=12; i++)
           {
               MessageBox.Show(((TextBox)(this.Controls[("txtbarcode" + i.ToString())])).Text);
           }

       }


问候
sarva


regards
sarva


private void lookControl()
{
      for(int i=1;i<=12;i++)

           {
  
//// find control here with ("txtbarcode"+i) ////

                Directcast(this.controls.find("txtbarcode" + i.ToString(),True).getvalue[0],Textbox).Text="";
              
           }
}



祝您编码愉快!
:)



Happy Coding!
:)


这篇关于在C#中的表单应用程序中找到文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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