获取文本框的文本是动态创建的 [英] getting the textbox's text which was created dynamically

查看:72
本文介绍了获取文本框的文本是动态创建的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我在运行时创建了多个TextBox es,还编写了TextBox es的click事件,当我单击TextBox即(在运行时创建的)时,我想获取<TextBox的c3>.

创建TextBox取决于数据库.

Hi to all
I had created a number of TextBoxes in runtime, I had also writen the click event for the TextBoxes, when I click on the TextBox i.e (which was created in runtime), I want to get the Text of TextBox .

Creating the TextBox depends on a database.

TextBox t = new TextBox();
t.Text = dr["temp1"].ToString();
t.BackColor = Color.CadetBlue;
t.WordWrap = true;
t.Multiline = true;
t.ReadOnly = true;
t.HideSelection = true;
t.Size = new Size(610, 50);
t.Name = "temptxt";
t.Click += new System.EventHandler(t_Click);
pan.Controls.Add(t);


我尝试了很多,但没有用.我还尝试过隐藏CheckBox,因为我不应该在那个地方使用CheckBox,但是我无法获得所单击的TextBoxText.


I had tried a lot but no use. I had also tried by keeping the CheckBox hidden, because I should not use the CheckBox at that place, but I am not able to get the Text of the clicked TextBox.

推荐答案

在Click事件处理程序中,您将有一个参数"sender"-这是导致事件的TextBox:
In the Click event handler, you will have a parameter "sender" - this is the TextBox that caused the event:
TextBox t = sender as TextBox;
if (t != null)
   {
   Console.WriteLIne(t.Text);
   }


TextBox
Click事件处理程序中使用以下代码
Use the following code in the Click event handler of the TextBox
void t_Click(object sender, EventArgs e)
{
    TextBox t1 = (TextBox)sender;
    string str = t1.Text; 
}


这篇关于获取文本框的文本是动态创建的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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