NET 控件数组代码想要调整下

有人能调整下么 代码如连接
想要的是这种:
通过 Button控件 创建5个textbox控件同时也创建5个timer控件
第二个控件控制timer运行
timer控件的事件 比如
timer1为textbox1 赋值 从1加到500
timer2为textbox2 赋值 从1加到500
一对一的这种

这样就行


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinFormsApp5
{
    public partial class Form1 : Form
    {
        Timer[] timers=new Timer[5];
        TextBox[] textBoxes=new TextBox[5];
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 5; i++)
            {
                Timer t = new Timer();
                TextBox tb = new TextBox();
                tb.Size = new Size(50,30);
                tb.Location = new Point(50,150+i*40);
                tb.Text = "0";
                t.Interval = 400+i*400;
                t.Tick += delegate { tb.Text=(int.Parse(tb.Text)+1).ToString(); };
                textBoxes[i] = tb;
                timers[i] = t;
                this.Controls.Add(tb);
            }
            for (int i = 0; i < 5; i++)
            {
                timers[i].Start();
            }
        }
    }
}

https://www.cnblogs.com/yunbo/archive/2009/08/13/1545659.html

img

form控件布置效果,如上图,两个按钮,两个textbox,两个timer,一一对应,分别控制的代码如下:


namespace answer_c
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }



        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            timer1.Interval = 100;
            timer1.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            string strN;
            if (textBox1.Text == ""){strN = "0";}
            else{strN = textBox1.Text;}
                
            
            int n = Convert.ToInt32(strN);
            textBox1.Text =Convert.ToString(n+1);
            if (textBox1.Text == "30") { timer1.Enabled = false; }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer2.Enabled = true;
            timer2.Interval = 100;
            timer2.Start();
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            string strN;
            if (textBox2.Text == "") { strN = "0"; }
            else { strN = textBox2.Text; }


            int n = Convert.ToInt32(strN);
            textBox2.Text = Convert.ToString(n + 1);
            if (textBox2.Text == "20") { timer2.Enabled = false; }
        }
    }
}

望采纳,也可以到我的博文看看其他的问题或控件处理

好的谢谢 我会关注的
其实主要想要学习下

  1. 如何通过代码创建控件的数组
  2. 如何做到每个控件数组精准的达到自己的预期
    所以才会提到一对一赋值
    timer(1) 对textbox(1)进行赋值
    timer(2) 对textbox(2)进行赋值

img

1