Source Code : Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TimerTest
{
public partial class Form1 : Form
{
Timer timer1 = new Timer();
int i;
public Form1()
{
InitializeComponent();
timer1.Interval = 1000;
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
i = int.Parse(label1.Text);
i++;
label1.Text = i.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Tick -= new EventHandler(timer1_Tick);
timer1.Enabled = false;
i = 0;
label1.Text = i.ToString();
}
}
}
Source Code : Form1.Designer.cs
namespace TimerTest
{
partial class Form1
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(118, 30);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(13, 13);
this.label1.TabIndex = 0;
this.label1.Text = "0";
//
// button1
//
this.button1.Location = new System.Drawing.Point(27, 76);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(90, 28);
this.button1.TabIndex = 1;
this.button1.Text = "Start Timer";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(133, 76);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(90, 28);
this.button2.TabIndex = 2;
this.button2.Text = "Stop Timer";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ClientSize = new System.Drawing.Size(258, 137);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = " Timer";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
}
}
Download :
exe
http://sites.google.com/site/ogremyfiles/TimerTest_EXE.rar
Source Code
http://sites.google.com/site/ogremyfiles/TimerTest_SourceCode.rar