如何选择带变量的文本框? [英] how to select a textbox with a variable?

查看:119
本文介绍了如何选择带变量的文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想选择一个指定的文本框,如:



i want to select a specified textbox like :

int k=15;
select textBoxk //  trying to select the textBox15





如何从外面发送数字15来选择textBox15?



how can i select textBox15 with sending the number 15 from outside?

推荐答案

您好,



试试这个:

Hi,

Try this:
Dictionary<string, TextBox> textBoxDictionary = new Dictionary<string, TextBox>();
public Form1() // constructor
{
      InitializeComponent();
      textBoxDictionary.Add("textBox1", textBox1);
      textBoxDictionary.Add("textBox2", textBox2);
      textBoxDictionary.Add("textBox3", textBox3);
      ...
}



现在,要设置特定文本框的文本,请尝试以下方法:


Now, to set the text of a specific text box, try this:

int k = 15;
textBoxDictionary["textBox" + k.ToString()].Text = "some text";



希望这有帮助。


Hope this helps.


我认为必须是:

i think it must be :
Dictionary<string,textbox> textBoxDictionary = new Dictionary<string,textbox>();



它说''预期类型''我不写TextBox。

我是对吗?


it says ''Type Expected'' when i dont write TextBox.
am i right?


你好b $ b

您可以使用以下代码:



Hi
You can use from bellow code:

-------------------------------------------------------------
TextBox[] textBox = new TextBox[NumberOfTextBoxYouNeed];
textBox[YourDestinationNumber].Text = "Your Text";







我希望它有帮助的




I hope it''s helpful


这篇关于如何选择带变量的文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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