Пример #1
0
        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);
            }
        }