111,074
社区成员




代码:
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下面有波浪线,该如何解决?谢谢