C#定时器出现错误的问题

ccbbcc CSDN会员 ccbbcc 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

代码:

using System;
using System.Windows.Forms;

public class TimerExampleForm : Form
{
    private Timer timer;
    private int counter = 0;
    private Label label;

    public TimerExampleForm()
    {
        // 初始化Label控件  
        label = new Label();
        label.Location = new System.Drawing.Point(50, 50);
        label.Size = new System.Drawing.Size(200, 30);
        this.Controls.Add(label);

        // 初始化Timer控件  
        timer = new Timer();
        timer.Interval = 1000; // 设置时间间隔为1000毫秒(1秒)  
        timer.Tick += new EventHandler(OnTimedEvent);
        timer.Start(); // 启动定时器  
    }

    private void OnTimedEvent(Object myObject, EventArgs myEventArgs)
    {
        // 在这里编写定时执行的代码  
        counter++;
        label.Text = "Counter: " + counter.ToString();
    }

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new TimerExampleForm());
    }
}

 

Timer下面有波浪线,该如何解决?谢谢

...全文

相关推荐

评论
收藏 已收藏
分享
返回顶部
ccbbcc CSDN会员
C# 111,129 成员 642,540 内容