//Variables used in the timing system
TimeSpan
_transitionTime=new TimeSpan(0,0,0,1,0);
float
_currentPercentage=0;
bool
_running=false;
public
float TransitionTime
{
get{return
(float)_transitionTime.TotalSeconds;}
set{_transitionTime=new
TimeSpan(0,0,0,0,(int)(1000*value));}
}
//The moment at which the transition begins
DateTime
_startTime;
//Called to start the transition off
public
void Go()
{
t=new
System.Threading.Timer(new TimerCallback(Tick),null,40,40);
this._currentPercentage=0;
_running=true;
_startTime=DateTime.Now;
Invalidate();
}
//Services the tick event and re-calculates the percentage done
void
Tick(object state)
{
TimeSpan
ts=DateTime.Now-this._startTime;
_currentPercentage=(float)(100f
/ this._transitionTime.TotalSeconds *
ts.TotalSeconds);
if(_currentPercentage>100)
_currentPercentage=100;
Invalidate();
}