hello i have a simple stopwatch which also works. but is add using System.Threading; it gave an error, i need Threading for my backgroundworkers
'Timer' is an ambiguous reference between 'System.Threading.Timer' and 'System.Windows.Forms.Timer'
Timer timer;
public MainForm()
{
InitializeComponent();
timer = new Timer();
timer.Tick += new EventHandler(timer_Tick);
}
void timer_Tick(object sender, EventArgs e)
{
ms++;
this.Refresh();
string strms = "";
string strss = "";
string strmm = "";
string strhh = "";
strms = GetStringValue(ms);
strss = GetStringValue(ss);
strmm = GetStringValue(mm);
strhh = GetStringValue(hh);
if (ms == 9)
{
ms = 0;
ss++;
strss = GetStringValue(ss);
if (ss == 59)
{
ss = 0;
mm++;
strmm = GetStringValue(mm);
if (mm == 59)
{
mm = 0;
hh++;
strhh = GetStringValue(hh);
if (hh == 12)
{
hh = 0;
}
}
}
}
strTime = strhh + ":" + strmm + ":" + strss;
lblTime.Text = strTime;
}
private void btnStart_Click(object sender, EventArgs e)
{
if (btnStart.Text == "&Start")
{
btnStart.Text = "&Stop";
timer.Start();
}
else
{
btnStart.Text ="&Start";
timer.Stop();
ms = 0;
ss = 0;
mm = 0;
hh = 0;
}
}
private string GetStringValue(int nValue)
{
string strValue = "00";
if (nValue == 0)
{
return strValue;
}
if (nValue < 10)
{
strValue = "0" + nValue.ToString();
return strValue;
}
return nValue.ToString();
}