如何在另一种在c中动态创建的方法中为文本框赋值 [英] how to assign values to textbox in another method which was dynamically created in c sharp

查看:16
本文介绍了如何在另一种在c中动态创建的方法中为文本框赋值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在cSharp中动态创建的开始暂停按钮方法中为文本框赋值

how to assign values to text box in start pause button method which was dynamically created in c sharp

 public void btn_addtimer_Click(object sender, EventArgs e)
    {
        var panel1 = new Panel() 
            { 
                Size = new Size(500, 180), 
                Location = new Point(10, i), 
                BorderStyle = BorderStyle.FixedSingle 
            };
        TextBox textseconds = new TextBox();
        textseconds.Name = "txtseconds";
        textseconds.Location = new Point(350, 50);
        textseconds.KeyPress += textseconds_KeyPress;
        panel1.Controls.Add(textseconds);


        Button startpause = new Button();
        startpause.Name = "btnstartpause";
        startpause.Text = "Start";
        startpause.Location = new Point(350, 80);
        startpause.Click += btnstartpause_Click;
        panel1.Controls.Add(startpause);

    }

推荐答案

使用 FindControl 和强制转换:

Use FindControl with a cast:

((TextBox)FindControl("textseconds")).Text = "Some text here";

这篇关于如何在另一种在c中动态创建的方法中为文本框赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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