简体   繁体   English

如何从动态文本框中获取文本

[英]How can I get the text from the dynamic textbox

I have used this code: 我使用了以下代码:

for (int i = 0; i < 10; i++)
{
    int page_valid = i + 1;
    this.Controls.Add(new TextBox() { Name = i.ToString(), Location = new Point(33, 210 + (i * 26)), Text = "" + page_valid + "." + " " + "Individual entrepreneur ", Size = new System.Drawing.Size(630, 20) });
}

How can I get the text from the dynamic textbox? 如何从动态文本框中获取文本?

You can access it via it's name 您可以通过它的名称访问它

string text = this.Controls["1"].Text;

If you wanna get the all texts you can use: 如果您想获取所有文本,可以使用:

this.Controls.OfType<TextBox>().Select(t => t.Text).ToArray();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM