timer in C#
im doing a project for browsing center. In that after the customer logs in he has to enter his browsing time. After entering that in a new window i have to display his reducing browsing time. can i do it with a use of timer control? if it is possible plz tell me the and i want some sample codings for that. plz help me...
Scott LyslePosted Oct 12, 2008, 9:24 PM
Sure, just use the time to decrement a count. For example, if you wanted to give them 60 minutes, you could create a time with the interval set to 60000 and on the tick event, decrement the time to go value by one minute, when the timer zeros out, shutdown the application. Of course there is nothing that would stop the user from closing the application but you could set up the application to notify you that they had terminated it.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CountDownTimer
{
public partial class Form1 : Form
{
private int mTimeToGo;
public Form1()
{
InitializeComponent();
mTimeToGo = 60;
label1.Text = "TTG: " + mTimeToGo.ToString();
}
private void timer1_Tick(object sender, EventArgs e)
{
mTimeToGo -= 1;
label1.Text = "TTG: " + mTimeToGo.ToString();
if (mTimeToGo == 0)
Application.Exit();
}
}
}