For some reason Ralfs solution did not work when I tested it, here is my modified version.
I would not recommend using the forms Timer btw. it can lead to problems with e.g. threading, better use a system Timer.
using System;
using System.Windows.Forms;
namespace WinFormsTimer1
{
public partial class Form1 : Form
{
private int[] myTimer = new[] { 10, 1, 3 };
public Form1()
{
InitializeComponent();
System.Windows.Forms.Timer MyTimer = new System.Windows.Forms.Timer();
MyTimer.Interval = (5000);
MyTimer.Tick += new EventHandler(Timer1_Tick);
MyTimer.Start();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Timer1_Tick(Object myObject, EventArgs myEventArgs)
{
this.label1.Text = myTimer[0].ToString() + " " + myTimer[1].ToString() + " " + myTimer[2].ToString();
if (myTimer[0] > 0)
{
myTimer[0] -= 1;
}
else if (myTimer[1] > 0)
{
myTimer[1] -= 1;
DialogResult Result = MessageBox.Show("The form will now be closed.", "Time Elapsed", MessageBoxButtons.OKCancel);
if (Result == DialogResult.Cancel)
{
myTimer[0] = 10;
myTimer[1] = 1;
myTimer[2] = 3;
}
else
{
this.Close();
}
}
else if (myTimer[2] > 0)
{
myTimer[2] -= 1;
}
else if (myTimer[2] == 0)
{
SendKeys.Send("\r");
}
}
}
}