如题,可以使用timer控件来实现,可以通过设置timer控件属性中的Interval来设置时间间隔(使用VS2019)
using System;
using System.Diagnostics;
using System.Windows.Forms;
namespace Test
{
public partial class Form3 : Form
{
private const string flash = "逐个文字显示Demo";
private int stopCount = flash.Length + 15;//停止时间
private int count = 0;
private bool finish = false;
public Form3()
{
InitializeComponent();
//启动计时器
timer1.Start();
label2.Text = "";
}
private void label1_Click(object sender, EventArgs e)
{
}
//timer的tick事件
private void timer_Display_Tick(object sender, EventArgs e)
{
if (finish == false)
{
label2.Text += flash.Substring(count, 1); //逐个显示文字
}
//累加计数
count++;
if (count == flash.Length)
{
finish = true;//文字显示完成
}
else if (count >= stopCount)
{
timer1.Stop();
this.Close();//关闭窗口
}
}
private void Button1_Click(object sender, EventArgs e)
{
}
}
}
标签:count,object,C#,flash,System,private,timer,逐个,winform
From: https://blog.51cto.com/u_16207345/6993376