AIM : Design an application that uses the concept of User Control (Stop Watch).
Source Code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace nit
{
public partial class UserControl1 : UserControl
{
int hr, min, sec;
public UserControl1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Start();
timer1.Interval = 1000;
}
private void timer1_Tick(object sender, EventArgs e)
{
sec++;
if (sec == 60)
{
min++;
sec = 0;
}
if (min == 60)
{
hr++;
min = 0;
}
label1.Text = hr.ToString();
label2.Text = min.ToString();
label3.Text = sec.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
timer1.Stop();
}
private void button3_Click(object sender, EventArgs e)
{
timer1.Stop();
hr = 0;
min = 0;
sec = 0;
label1.Text = hr.ToString();
label2.Text = min.ToString();
label3.Text = sec.ToString();
}
}
}
Output: