César Goulart

César Goulart

  • NA
  • 46
  • 2.4k

add minutes to countdown

Oct 6 2019 8:21 PM
Hi, 
 
I have a little program an countdown, and i want to have a button(button3) to add one minute to the time while the countdown is active. 
 
thanks
 
  1. namespace timer  
  2. {  
  3.     public partial class Form1 : Form  
  4.     {  
  5.         private int TotalSeconds;  
  6.   
  7.         public Form1()  
  8.         {  
  9.             InitializeComponent();  
  10.   
  11.   
  12.         }  
  13.   
  14.         private void timer1_Tick(object sender, EventArgs e)  
  15.         {  
  16.             if (TotalSeconds > 0)  
  17.   
  18.             {  
  19.                 TotalSeconds--;  
  20.                 int minutes = TotalSeconds / 60;  
  21.                 int seconds = TotalSeconds - (minutes * 60);  
  22.                 this.label1.Text = minutes.ToString() + ":" + seconds.ToString();  
  23.             }  
  24.             else  
  25.   
  26.             {  
  27.                 this.timer1.Stop();  
  28.                 MessageBox.Show("fim");  
  29.             }  
  30.   
  31.   
  32.         }  
  33.   
  34.   
  35.   
  36.         private void Form1_Load(object sender, EventArgs e)  
  37.         {  
  38.             for (int i = 0; i < 61; i++)  
  39.             {  
  40.                 this.comboBox1.Items.Add(i.ToString("D2"));  
  41.                 this.comboBox2.Items.Add(i.ToString("D2"));  
  42.   
  43.   
  44.             }  
  45.   
  46.             string minutos = ConfigurationManager.AppSettings["minutos"];  
  47.             string segundos = ConfigurationManager.AppSettings["segundos"];  
  48.   
  49.             //label3.Text = minutos;  
  50.   
  51.   
  52.             this.comboBox1.SelectedIndex = Int32.Parse(minutos);  
  53.             this.comboBox2.SelectedIndex = Int32.Parse(segundos);  
  54.   
  55.         }  
  56.   
  57.         private void button1_Click_1(object sender, EventArgs e)  
  58.         {  
  59.   
  60.             timer1.Start();  
  61.         }  
  62.   
  63.         private void button2_Click(object sender, EventArgs e)  
  64.         {  
  65.             timer1.Stop();  
  66.         }  
  67.   
  68.   
  69.   
  70.         private void button3_Click(object sender, EventArgs e)  
  71.         {  
  72.             timer1.Start();  
  73.         }  
  74.   
  75.   
  76.   
  77.         public void button1_Click(object sender, EventArgs e)  
  78.         {  
  79.             int minutes = int.Parse(this.comboBox1.SelectedItem.ToString());  
  80.             int seconds = int.Parse(this.comboBox2.SelectedItem.ToString());  
  81.             TotalSeconds = (minutes * 60) + seconds;  
  82.   
  83.             this.timer1.Enabled = true;  
  84.         }  
  85.   
  86.         private void button2_Click_1(object sender, EventArgs e)  
  87.         {  
  88.             this.timer1.Stop();  
  89.         }  
  90.   
  91.         private void label4_Click(object sender, EventArgs e)  
  92.         {  
  93.   
  94.         }  
  95.   
  96.         private void button3_Click_1(object sender, EventArgs e)  
  97.         {     
  98.             //**codigo que nao funciona  
  99.   
  100.             //TotalSeconds += 60;  
  101.         }  
  102.     }  
  103. }  
 

Answers (1)