是有一个字符串数组,想在TextBox上逐行输出,用过Timer和sleep(1000)都没用,都是直接把全部内容都输出在了TextBox上。请问有什么好的方法吗?谢谢。
sleep(1000)
可以用,不过下面加上:
Application.DoEvents();
用Timer是可以的,如下图所示,代码实现如下,仅供参考。
namespace _02_Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
timer1.Enabled = true;
timer1.Interval = 1000;
}
string[] str = { "123", "456", "567", "8910" };
int i = 0;
private void timer1_Tick(object sender, EventArgs e)
{
if(i==str.Length)
{
return;
}
textBox1.AppendText(str[i++]+"\r\n");
}
}
}