现在它只能像8..7..6 ... 5 ..秒一样倒计时,Timer1的间隔设置为1000ms 我希望如果用户将numericupdown1更改为9,那么改为像现在一样计算秒数,它会将其计为分钟并将其显示为:01(分钟):10(秒)
这是Timer1_Tick事件的代码:
private void timer1_Tick(object sender, EventArgs e)
{
try
{
numbers_radar = Convert.ToInt64(numericUpDown1.Value);
numbers_satellite = Convert.ToInt64(numericUpDown2.Value);
if (numbers_radar <= 0 || numbers_satellite <= 0)
{
timer1.Stop();
button1.Enabled = true;
numericUpDown1.Enabled = true;
numericUpDown2.Enabled = true;
MessageBox.Show("Value cannot be zero or below zero");
numericUpDown1.Text = "";
numericUpDown2.Text = "";
}
else
{
Numbers_Timer_radar = Numbers_Timer_radar + 1;
Numbers_Timer_satellite = Numbers_Timer_satellite + 1;
if (Numbers_Timer_radar >= numbers_radar)
{
try
{
filesdownload();
number_of_files_in_current_directory = Directory.GetFiles(sf, "radar*.png");
label13.Text = "Current Number Of Files In The Selected Directory Are: " + number_of_files_in_current_directory.Length;
button1.Enabled = false;
Numbers_Timer_radar = 0;
}
catch (Exception Local_Timer1_Exceptions)
{
Logger.Write("Timer1 Errors : " + Local_Timer1_Exceptions);
}
}
if (Numbers_Timer_satellite >= numbers_satellite)
{
satellite_downloads();
number_of_satellite_files_in_current_directory = Directory.GetFiles(satellite_dir, "satellite*.png");
label8.Text = "Current Number Of Files In The Selected Directory Are: " + number_of_satellite_files_in_current_directory.Length;
button1.Enabled = false;
Numbers_Timer_satellite = 0;
}
time_left_radar = numbers_radar - Numbers_Timer_radar;
time_left_satellite = numbers_satellite - Numbers_Timer_satellite;
//string t = GetTime((int)time_left_radar);
label21.Text = time_left_radar.ToString();
label22.Text = time_left_satellite.ToString();
label1.Text = "Next image radar will be download in: ";
label5.Text = "Next image satellite will be download in: ";
}
}
catch (Exception General_Exceptions)
{
Logger.Write("Show if numbers have wrong string input" + numbers_radar);
Logger.Write("Show if numbers have wrong string input" + numbers_satellite);
timer1.Stop();
Logger.Write("Exception: " + General_Exceptions + Environment.NewLine);
//numericUpDown1.Clear();
//numericUpDown2.Clear();
button1.Enabled = true;
numericUpDown1.Enabled = true;
numericUpDown2.Enabled = true;
Numbers_Timer_radar = 0;
Numbers_Timer_satellite = 0;
}
}
time_left_radar和time_left_satellite都是长变量 而在label21和label22中看到秒向后计数8..7..6..etc我希望它像: 01(分钟):10(秒).. 01:9..01:8 ......或01:09..01:08 ...
所以它将计算分钟和秒数。
我试图在带有GetTime方法的timer1_tick事件中使用它,但它没有用。 GetTime方法代码是:
public string GetTime(int Time)
{
//Seconds
Sec = Time % 60;
//Minutes
Min = ((Time - Sec) / 60) % 60;
//Hours
Hrs = ((Time - (Sec + (Min * 60))) / 3600) % 60;
return Hrs.ToString("00") + ":" +
Min.ToString("00") + ":" +
Sec.ToString("00");
}
感谢您的帮助。