正在从用户定义的控件列表中检索文本... [英] Retrieving text from the user defined controls list...

查看:80
本文介绍了正在从用户定义的控件列表中检索文本...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在我的应用程序中,我使用的是用户定义的文本框.现在,我想从该文本框中获取值.谁能帮我吗?

预先感谢.

Hi to all,

in my application I am using a userdefined textbox. Now I want to get the value from that textbox. Can anyone help me?

Thanks in advance.

推荐答案

我不确定用户定义的文本框"是什么意思.
您的意思是您在运行时创建了一个,并且想要从中获取信息吗?
如果是这样,那么有两种方法可以实现:
1)创建它时,请将引用的副本保留在类级别变量中:
I am not sure what you mean by "userdefined textbox".
Do you mean you created one at runtime, and want to get the information from it?
If so, then there are two ways you can do that:
1) When you create it, keep a copy of the reference in a class level variable:
private TextBox myTextBox;
private void CreateTextBox(string initialText)
   {
   myTextBox = new TextBox();
   myTextBox.Text = initialText;
   Controls.Add(myTextBox);
   }


2)您可以通过迭代形式通过Controls数组访问它:


2) You can access it via the forms Controls array by iteration:

foreach (Control c in Controls)
   {
   TextBox t = c as TextBox;
   if (t != null)
      {
      Console.WriteLine(t.Text);
      }
   }


3)您可以给它命名,然后直接通过Controls数组访问它


3) You can give it a name, and access it directly via the Controls array

private void CreateTextBox(string initialText)
   {
   TextBox myTextBox = new TextBox();
   myTextBox.Text = initialText;
   myTextBox.Name = "RunTimeTextBox";
   Controls.Add(myTextBox);
   }
private TextBox GetRunTimeTextBox(string name)
   {
   return Controls[name] as TextBox;
   }


请注意,名称对于表单实例必须是唯一的!

如果这不是您要尝试的操作,我们将需要更多详细信息.

[edit]删除了加倍的< pre>标签-OriginalGriff [/edit]


Note that the name must be unique to the form instance!

If this isn''t what you are trying to do, we will need more details.

[edit]Removed doubled <pre> tags - OriginalGriff[/edit]


这篇关于正在从用户定义的控件列表中检索文本...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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