计时器在c#中流逝时如何显示消息框
我将时间间隔设为100.当计时器结束时,显示消息框但我的屏幕充满了消息框。 如何通过一个指示计时器已过的消息框来停止它。 这是我的代码……你能指导我在哪里给停止计时器……
namespace timer1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void timer1_Tick(object sender, EventArgs e) { Timer t = new Timer(); t.Interval = 100; timer1.Enabled = true; timer1.Tick += new System.EventHandler(OnTimerEvent); } private void OnTimerEvent(object sender, EventArgs e) { MessageBox.Show("time over"); } } }
我猜(因为你不提供代码),在中断服务程序中:
public void YourTimer_Tick(object sender, EventArgs e) { YourTimer.Stop(); MessageBox.Show("You message..."); }