System.Windows.Forms.Timer does not exist
本文关键字:not exist does Timer Windows Forms System | 更新日期: 2023-09-27 17:50:50
我正在尝试在c#中设置定时器。在"使用"部分,我包括了这个
using System.Windows.Forms.Timer;
我的定时器是这样的:
private Timer timer1;
public void InitTimer()
{
timer1 = new Timer();
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Interval = 1000;
timer1.Start();
}
然而,"定时器"下划线,我得到这个错误:
"类型命名空间'Timer'找不到(您是否缺少using指令还是程序集引用?)"
我以为这是默认包含的。如果没有,我需要包括什么作为参考?
谢谢。
命名空间应为:
using System.Windows.Forms;
Timer
是该命名空间中的类。
如果它不是Windows窗体应用程序,则需要添加对System.Windows.Forms DLL的引用。如果是的话,请尽可能贴出完整的片段。