<p>So, a while back I wrote a simple program to time my practice tests. I'm done with the ACT now, and I found this program lying around on my computer, so I thought I'd post it here in the case that someone else might find it useful. It's for Windows (tested on XP and Vista) and requires the .NET Framework 2.0.</p>
<p>It keeps a log of messages so you can keep precise track of time, including intervals where you paused the timer. It also will give you a message and make a beep when five minutes remain on a test. If you minimize the window, it will show the time remaining on the task bar.</p>
<p>I might consider extending it sometime. If I were to extend it, I'd probably rewrite it and store the timing information (names of the tests + how long each lasts) in a text file so people could add their own tests to it.</p>
<p>As for the source code, here you go. :)</p>
<p>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;</p>
<p>namespace ACT<em>Test</em>Timer
{
public partial class MainForm : Form
{
private Timer timer = new Timer();
private DateTime startTime;
private DateTime testEndTime;
private bool fiveMinuteWarningGiven = false;
private bool isTiming = false;</p>
<pre><code> private DateTime pausedTime;
private bool justUnpaused = false;
private TimeSpan accumulatedPauseTime;
public MainForm()
{
this.Icon = Resource1.ACTLogo;
timer.Tick += new EventHandler(OnTimerTick);
InitializeComponent();
}
private void AddMessage(string text)
{
listViewMessages.Items.Add(DateTime.Now.ToString() + ": " + text);
}
private void Pause()
{
isTiming = false;
timer.Stop();
pausedTime = DateTime.Now;
buttonPause.Text = "Continue";
AddMessage("Timing is paused.");
}
private void Unpause()
{
isTiming = true;
justUnpaused = true;
timer.Start();
buttonPause.Text = "Pause";
AddMessage("Timing is resumed.");
}
void OnTimerTick(object sender, EventArgs e)
{
DateTime now = DateTime.Now;
if (justUnpaused)
{
TimeSpan pausedInterval = now - pausedTime;
accumulatedPauseTime += pausedInterval;
justUnpaused = false;
}
TimeSpan interval = testEndTime - now + accumulatedPauseTime;
string secondsString = "";
if (interval.Seconds < 10)
secondsString = "0" + interval.Seconds.ToString();
else
secondsString = interval.Seconds.ToString();
string minutesString = "";
if (interval.Minutes < 10)
minutesString = "0" + interval.Minutes.ToString();
else
minutesString = interval.Minutes.ToString();
labelTimeRemaining.Text = minutesString + ":" + secondsString;
if (interval.Minutes == 5 && interval.Seconds == 0 && !fiveMinuteWarningGiven)
{
AddMessage("Five minutes remain!");
System.Media.SystemSounds.Exclamation.Play();
fiveMinuteWarningGiven = true;
}
if (interval.Minutes == 0 && interval.Seconds == 0)
{
timer.Stop();
AddMessage("Time's up!");
System.Media.SystemSounds.Exclamation.Play();
}
if (WindowState == FormWindowState.Minimized)
Text = labelTimeRemaining.Text;
else
Text = "ACT Test Timer -- by Zach Conn";
}
private void MainForm_Load(object sender, EventArgs e)
{
}
private void buttonBeginTiming_Click(object sender, EventArgs e)
{
bool tempPaused = false;
if (isTiming)
{
Pause();
tempPaused = true;
}
if ((isTiming || buttonPause.Text == "Continue") &&
MessageBox.Show("Are you sure you want to start timing a new test? The test currently being timed will " +
"no longer be timed!", "Start new test?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
DialogResult.No)
{
if (tempPaused)
Unpause();
return;
}
string testName = "";
if (radioButtonEnglish.Checked)
{
testName = "English";
}
else if (radioButtonMathematics.Checked)
{
testName = "Mathematics";
}
else if (radioButtonReading.Checked)
{
testName = "Reading";
}
else if (radioButtonScience.Checked)
{
testName = "Science";
}
if (isTiming || buttonPause.Text == "Continue")
AddMessage("Stopped timing current test.");
AddMessage("Began timing " + testName + " test.");
startTime = DateTime.Now;
testEndTime = DateTime.Now;
switch (testName)
{
case "English":
testEndTime = testEndTime.AddMinutes(45);
break;
case "Mathematics":
testEndTime = testEndTime.AddMinutes(60);
break;
case "Reading":
testEndTime = testEndTime.AddMinutes(35);
break;
case "Science":
testEndTime = testEndTime.AddMinutes(35);
break;
}
timer.Interval = 100;
timer.Start();
fiveMinuteWarningGiven = false;
isTiming = true;
buttonPause.Text = "Pause";
accumulatedPauseTime = TimeSpan.Zero;
}
private void buttonPause_Click(object sender, EventArgs e)
{
if (isTiming)
Pause();
else if (buttonPause.Text == "Continue")
Unpause();
}
}
</code></pre>
<p>}
</p>
<p>It's very sloppy and poorly written--I wrote this program really fast and with little care. :)</p>
<p>Hey nilkn, thank you for sharing, but I'm having trouble opening the program. Every time I'd try to open the application, I would receive a message that says it failed to open. =[ Is it just me?</p>
<p>I'm pretty sure this is the problem though-I don't know or probably have ".NET Framework 2.0."... I guess I'll google it.
Thanks again.</p>
<p>This may sound so dumb. . . but how on earth do you learn to do that stuff? We don't have any Computer Science classes at our school, just basic Computer and Computer 2</p>
<p>Great program---I've taken a few practice tests today, and it's been quite helpful. No more will I have to fumble around setting my cell phone alarm to try and time myself accurately. :) Thanks.</p>