private void Form1_Load(object sender, EventArgs e)
        {
            Button btn = new Button();
            btn.Text = "清空";
            btn.Name = "btn1";
            btn.Location = new Point(100,100);
            this.Controls.Add(btn);
            TextBox txt = new TextBox();
            txt.Text = "123";
            txt.Name = "txt1";
            txt.Location = new Point(200,100);
            this.Controls.Add(txt);
        }
这样在程序运行以后会生成一个按钮和一个文本框~  现在我想在点击按钮的时候 清空文本框中的内容~  现在的问题是:在程序没有运行的时候是没有控件的,也没有控件的名字~无法对文本框的内容作清空的处理` 尝试过写一个自定义的事件~ 当点击按钮的时候去调用~  可是在事件还是无法去获得文本的内容  不知道如何清空`   我们的两个总经理都是外行`不懂语言~是做餐饮方面的`用的是C#写的软件~天天逼我写~我能力有限~真不知道这个问题怎么解决`请大家帮帮忙~ 解决就结贴~~

解决方案 »

  1.   

     private void Form1_Load(object sender, EventArgs e)
            {
                Button btn = new Button();
                btn.Text = "清空";
                btn.Name = "btn1";
                btn.Location = new Point(100, 100);
                btn.Click += new EventHandler(btn_Click);
                this.Controls.Add(btn);
                TextBox txt = new TextBox();
                txt.Text = "123";
                txt.Name = "txt1";
                txt.Location = new Point(200, 100);
                this.Controls.Add(txt);         }        void btn_Click(object sender, EventArgs e)
            {
                ((TextBox)this.Controls["txt1"]).Text = "";
            }
      

  2.   

             private void Form1_Load(object sender, EventArgs e)
            {
                Button btn = new Button();
                btn.Text = "清空";
                btn.Name = "btn1";
                btn.Location = new Point(100,100);
                this.Controls.Add(btn);
                btn.Click+=new EventHandler(btn_Click);
                  
                TextBox txt = new TextBox();
                txt
                txt.Text = "123";
                txt.Name = "txt1";
                txt.Location = new Point(200,100);
                this.Controls.Add(txt);
            } 
            void btn_Click(object sender,EventArgs e)
            {
             ...
             }...很少写WINFORM
      

  3.   


     发表于:2008-08-27 17:02:102楼 得分:0 
    C# code private void Form1_Load(object sender, EventArgs e)
            {
                Button btn = new Button();
                btn.Text = "清空";
                btn.Name = "btn1";
                btn.Location = new Point(100, 100);
                btn.Click += new EventHandler(btn_Click);
                this.Controls.Add(btn);
                TextBox txt = new TextBox();
                txt.Text = "123";
                txt.Name = "txt1";
                txt.Location = new Point(200, 100);
                this.Controls.Add(txt);         }        void btn_Click(object sender, EventArgs e)
            {
                ((TextBox)this.Controls["txt1"]).Text = "";
            } 
    这个就行