C#怎么弄时钟事件

C#怎么弄时钟事件,第1张

首先,申明一个时钟控件,可以用VS 拖

private Timer _testTimer = new Timer()

时钟控件上有一个 Tick()事件

private _testTimer_Tick(object sender,EventArgs e){

// 在这里写你要做的事情

}

接着你可以启动这个事件

private TestForm_Load(object sender, EventArgs e){

_testTimer.Start()

}

这样就可以了,当然,也可以取消事件

private TestForm_Closing(object sender, EventArgs e){

_testTimer.Stop()

}

稍微补充以下,你设置Timer的Interval,每当Inerval到达,Timer就会被触发,这个时候就是tick事件了。

如果你有自己订制的事件,比如

myTimer.Tick += new EventHandler(你的事件方法名称)

那么当Timer被激活的时候,就会运行你的方法,而且是订了Interval之后,就会定期运行的。

public static void Iconflash( )

 {

            int i =0

            Icon ico1 = new Icon("1.ico")

            Icon ico2 = new Icon("2.ico")

            NotifyIcon NtfIcon = new NotifyIcon() 

            Timer time = new Timer()

            NtfIcon.Icon = ico1

             //增加事件处理函数

            time.Tick+= time_Tick

            time.Enabled = true

            //立即引发事件

            time.OnTick(EventArgs.Empty)

 }

 void time_Tick(object sender, EventArgs e)

   {

       //……

   }


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11562007.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存