向数组中动态添加元素

本文关键字:添加 元素 动态 数组 | 更新日期: 2023-09-27 18:20:11

如何从文本框中动态获取数组值?并将这些值打印在一个名为"ArrLbl"的标签中,间隔3秒。

我用线程线程,睡眠!但只有当我在每个线程后面放置MessageBox时,它才有效。thread.sleep

Visual Studio 2012 中的windows窗体应用程序

我是的初学者

请帮帮我

向数组中动态添加元素

您不想在程序中使用Thread.Sleep,因为Thread.Sleep会在睡眠期间阻止程序运行。它不会对点击和移动等做出响应。你想要的是一个定时器,它会让你的程序正常运行,并在3秒的间隔内引发一个事件。

你可以这样做:

public class MyFrom : Form {
    private Timer timer = new Timer();
    public MyForm() {
        timer.Interval = 3000; // The interval is in ms
        timer.Tick += new TimerTick;
        timer.Start();
    }
    private void TimerTick(object sender, EventArgs e) {
        // Get the value from your text boxes here.
    }
}