private void timer1_Tick(object sender, EventArgs e) { if (taskbar > 50) { taskbar = 0; } if (taskbar < 20 && taskbar >= 0) { this.Text = (miliseconds / 4) + " seconds left!"; //TaskbarProgress.SetValue(this.Handle, progressBar.Value, progressBar.Maximum); } if (taskbar >= 20 && taskbar <= 40) { this.Text = (elapsed_progress.Maximum / 4) - (miliseconds / 4) + " seconds elapsed!"; //TaskbarProgress.SetValue(this.Handle, elapsed_progress.Value, elapsed_progress.Maximum); } if (taskbar > 40 && taskbar <= 50) { this.Text = (elapsed_progress.Maximum / 4) + " seconds countdown"; } taskbar++; TaskbarProgress.SetValue(this.Handle, progressBar.Value, progressBar.Maximum); miliseconds--; progressBar.Value = miliseconds; time_label.Text = (miliseconds / 4) + " seconds left!"; elapsed_progress.Value = progressBar.Maximum - progressBar.Value; elapsed.Text = (elapsed_progress.Maximum / 4) - (miliseconds / 4) + " seconds elapsed!"; if (miliseconds == 0) { timer1.Enabled = false; time_label.Text = "Countdown expired!"; timer2.Enabled = true; pause.Visible = false; this.Text = "Countdown expired!"; ModifyProgressBarColor.SetState(elapsed_progress, 2); ModifyProgressBarColor.SetState(progressBar, 2); TaskbarProgress.SetValue(this.Handle, progressBar.Maximum, progressBar.Maximum); TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Error); } }
private void pause_Click(object sender, EventArgs e) { if (pause_clicked == 0) { pause_clicked = 1; pause.Text = "Resume the countdown"; timer1.Enabled = false; ModifyProgressBarColor.SetState(elapsed_progress, 3); ModifyProgressBarColor.SetState(progressBar, 3); TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Paused); } else { pause_clicked = 0; pause.Text = "Pause the countdown"; ModifyProgressBarColor.SetState(elapsed_progress, 1); ModifyProgressBarColor.SetState(progressBar, 1); timer1.Enabled = true; TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Normal); } }
private void button1_Click(object sender, EventArgs e) { if (!start_clicked) { //Composing the time in h,m,s if (hours_input.Text == "") { hours_input.Text = "00"; } if (minutes_input.Text == "") { minutes_input.Text = "00"; } if (seconds_input.Text == "") { seconds_input.Text = "00"; } for (int i = 0; i <= 9; i++) { if (Convert.ToInt32(hours_input.Text) == i) { hours_input.Text = "0" + i; } if (Convert.ToInt32(minutes_input.Text) == i) { minutes_input.Text = "0" + i; } if (Convert.ToInt32(seconds_input.Text) == i) { seconds_input.Text = "0" + i; } } int hours, minutes, seconds; hours = Convert.ToInt32(hours_input.Text); minutes = Convert.ToInt32(minutes_input.Text); seconds = Convert.ToInt32(seconds_input.Text); //Composing the time in miliseconds miliseconds = (hours * 3600 + minutes * 60 + seconds) * 4 + 1; progressBar.Maximum = miliseconds - 1; progressBar.Value = miliseconds - 1; elapsed_progress.Maximum = progressBar.Maximum; //Starting countdown timer1.Enabled = true; progressBar.Visible = true; time_label.Visible = true; elapsed_progress.Visible = true; elapsed.Visible = true; taskbar = 0; seconds_input.ReadOnly = true; minutes_input.ReadOnly = true; hours_input.ReadOnly = true; pause.Visible = true; //Setting the stop button start_clicked = true; button1.Text = "Stop the countdown"; } else { start_clicked = false; button1.Text = "Start the countdown"; button1.Enabled = false; timer2.Enabled = true; timer1.Enabled = false; this.Text = "Countdown stopped!"; time_label.Text = "Countdown stopped!"; pause.Visible = false; ModifyProgressBarColor.SetState(elapsed_progress, 2); ModifyProgressBarColor.SetState(progressBar, 2); TaskbarProgress.SetState(this.Handle, TaskbarProgress.TaskbarStates.Error); } }