如何设置计数器并每3秒递增1并将其显示在标签中

时间:2019-04-23 07:00:23

标签: c#

 private void timer3_Tick(object sender, EventArgs e)
 {
 }

1 个答案:

答案 0 :(得分:0)

这是执行此操作的完整代码。只需在窗口上添加一个名为“ label1”的标签即可。

public partial class Form1 : Form
{

    private Timer timer3;
    private int counter;

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        counter = 0;

        timer3 = new Timer();
        timer3.Interval = 3000;
        timer3.Tick += Timer3_Tick;
        timer3.Start();
    }

    private void Timer3_Tick(object sender, EventArgs e)
    {
        counter++;
        label1.Text = counter.ToString();
    }
}