using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace CountDownTimers
{
public class Fivemintimer
{
Timer T = new Timer();
int Minutes = 5;
int Seconds = 0;
public Fivemintimer()
{
T.Interval = 1000;
T.Tick += new EventHandler(T_Tick);
}
public delegate void onTimerFinishedDelegate();
public event onTimerFinishedDelegate onTimerFinished;
public delegate void onTimerChanged(FIVETimerEventArgs args);
public event onTimerChanged onTimerTick;
void T_Tick(object sender, EventArgs e)
{
if (Minutes == 0 && Seconds == 0)
{
T.Stop();
if (onTimerFinished != null)
{
onTimerFinished();
}
}
else
{
if (Seconds == 0)
{
Seconds = 59;
Minutes--;
}
else
{
Seconds--;
}
}
if (onTimerTick != null)
{
onTimerTick(new FIVETimerEventArgs(Minutes, Seconds));
}
}
public void PlayPause()
{
if (T.Enabled)
{
T.Stop();
}
else
{
T.Start();
}
}
public void Reset()
{
Minutes = 5;
Seconds = 0;
}
public bool Enabled
{
get
{
return T.Enabled;
}
}
}
public class FIVETimerEventArgs : EventArgs
{
public string TimeLeft;
public FIVETimerEventArgs(int min, int sec)
{
string S;
if (sec < 10)
{
S = "0" + sec.ToString();
}
else
{
S = sec.ToString();
}
TimeLeft = min.ToString() + ":" + S;
}
}
}
0 comments:
Post a Comment
Note: only a member of this blog may post a comment.