3 つのテキスト ボックス (時間、分、秒)、開始、一時停止、停止ボタンがあり、ラベルを使用して現在のタイマーを表示しています。間隔のタイマーもあります1000
。私の質問は、ラベルを使用して時間を表示しないのはなぜですか? それ以外はすべて機能しますが、テキストボックスに値を入力したことが登録されません。
コード
開始タイマー: private void startbutton_Click(object sender, EventArgs e)
{
if (paused != true) //Timer is not paused (active)
{
int.TryParse(textBoxhrs.Text, out hours);
int.TryParse(textBoxmin.Text, out minutes);
int.TryParse(textBoxsec.Text, out seconds);
if (hours >= 1 || (minutes >= 1) || (seconds >= 1))
//If there is at least one integer entered in any of the 3 boxes, executes; else - //throws an exception
{
startbutton.Enabled = true;
pausebutton.Enabled = true; //changed the value to 'true'
stopbutton.Enabled = true; //changed the value to 'true'
textBoxhrs.Enabled = false;
textBoxmin.Enabled = false;
textBoxsec.Enabled = false;
}
else
{
MessageBox.Show("Enter at least one integer!");
}
}
}
private void stopbutton_Click(object sender, EventArgs e)
{
// Stop the timer.
paused = false;
timer1.Enabled = false;
startbutton.Enabled = true; //changed to true
stopbutton.Enabled = false; //changed to false
pausebutton.Enabled = false; //changed to false
textBoxsec.Clear();
textBoxmin.Clear();
textBoxhrs.Clear();
textBoxhrs.Enabled = true;
textBoxsec.Enabled = true;
textBoxmin.Enabled = true;
textBoxhrs.Enabled = true;
lblHr1.Text = "00";
lblMin1.Text = "00";
lblSec1.Text = "00";
MessageBox.Show("Timer is Stopped, to re-start press <Start>"); //updated to give user a chance to run the timer again after stoppage.
}
一時停止ボタン:
private void pausebutton_Click(object sender, EventArgs e)
{
// Pause the timer.
timer1.Enabled = false;
paused = true; //
startbutton.Enabled = true; // changed to true
pausebutton.Enabled = false; //changed to false
}
タイマー:
private void timer1_Tick(object sender, EventArgs e)
{
// Verify if the time didn't pass.
if ((minutes == 0) && (hours == 0) && (seconds == 0))
{
// If the time is over, clear all settings and fields.
// Also, show the message, notifying that the time is over.
timer1.Enabled = false;
MessageBox.Show(textBoxMsg.Text);
pausebutton.Enabled = false;
stopbutton.Enabled = false;
startbutton.Enabled = true;
textBoxMsg.Clear();
textBoxsec.Clear();
textBoxmin.Clear();
textBoxhrs.Enabled = true;
textBoxMsg.Enabled = true;
textBoxsec.Enabled = true;
textBoxmin.Enabled = true;
textBoxhrs.Enabled = true;
lblHr1.Text = "00";
lblMin1.Text = "00";
lblSec1.Text = "00";
}
else
{
// Else continue counting.
if (seconds < 1)
{
seconds = 59;
if (minutes == 0)
{
minutes = 59;
if (hours != 0)
hours -= 1;
}
else
{
minutes -= 1;
}
}
else
seconds -= 1;
// Display the current values of hours, minutes and seconds in
// the corresponding fields.
lblHr1.Text = hours.ToString();
lblMin1.Text = minutes.ToString();
lblSec1.Text = seconds.ToString();
}
}