簡體   English   中英

如何在C#中使用計時器時顯示消息框

[英]how to display a message box when timer elapses in 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...");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM