Add timer to a Windows Forms application

后端 未结 3 1554
抹茶落季
抹茶落季 2020-11-29 06:41

I want to add a timer rather than a countdown which automatically starts when the form loads. Starting time should be 45 minutes and once it ends, i.e. on reaching 0 minute

相关标签:
3条回答
  • 2020-11-29 07:21

    Download http://download.cnet.com/Free-Desktop-Timer/3000-2350_4-75415517.html

    Then add a button or something on the form and inside its event, just open this app ie:

    {

    Process.Start(@"C:\Program Files (x86)\Free Desktop Timer\DesktopTimer");

    }

    0 讨论(0)
  • 2020-11-29 07:34

    Something like this in your form main. Double click the form in the visual editor to create the form load event.

     Timer Clock=new Timer();
     Clock.Interval=2700000; // not sure if this length of time will work 
     Clock.Start();
     Clock.Tick+=new EventHandler(Timer_Tick);
    

    Then add an event handler to do something when the timer fires.

      public void Timer_Tick(object sender,EventArgs eArgs)
      {
        if(sender==Clock)
        {
          // do something here      
        }
      }
    
    0 讨论(0)
  • 2020-11-29 07:37

    Bit more detail:

        private void Form1_Load(object sender, EventArgs e)
        {
            Timer MyTimer = new Timer();
            MyTimer.Interval = (45 * 60 * 1000); // 45 mins
            MyTimer.Tick += new EventHandler(MyTimer_Tick);
            MyTimer.Start();
        }
    
        private void MyTimer_Tick(object sender, EventArgs e)
        {
            MessageBox.Show("The form will now be closed.", "Time Elapsed");
            this.Close();
        }
    
    0 讨论(0)
提交回复
热议问题