c# - 如何在计时器超时时显示消息框 [英] how to display a message box when timer elapses in c#

查看:27
本文介绍了c# - 如何在计时器超时时显示消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将我的时间间隔设置为 100.当计时器结束时,会显示消息框,但我的屏幕上充满了消息框.我应该如何用一个消息框来停止它,指示计时器已过.这是我的代码......你能指导我在哪里给停止计时器......

I gave my time interval as 100. when the timer elapsed the message box is displayed but my screen is flooded with message boxes. How should i stop it with one message box indicating timer elapsed. Here's my code... Can you guide me where to give stop timer...

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");

        }

    }
}

推荐答案

我猜(因为你没有提供代码),在中断服务程序中:

I guess (as you don't provide code), in the Interrupt Service Routine:

public void YourTimer_Tick(object sender, EventArgs e)
{
      YourTimer.Stop();
      MessageBox.Show("You message...");
}

这篇关于c# - 如何在计时器超时时显示消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆