代码如下:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace YYS { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } private void AddList() { DateTime dt = DateTime.Now; ListDate(dt); if (list == null || list.Count == 0) return; if (this.listboxliebiao.Items.Count > 0) { this.listboxliebiao.Items.Clear(); } foreach (DateTime item in list) { listboxliebiao.Items.Add(item); } } private string ListItem(string str) { string strName = ""; DateTime dt = Convert.ToDateTime(str); return strName; } private List<DateTime> list ; private void ListDate(DateTime dt) { if (dt.Minute < 30) { dt = dt.AddMinutes(-dt.Minute); } else { dt = dt.AddMinutes(60 - dt.Minute); } if (this.radioButton1.Checked) { list = new List<DateTime>(); DateTime date = new DateTime(); date = dt.AddHours(-12); for (int i = 0; i < 24; i++) { date = date.AddMinutes(30); list.Add(date); } } else if(this.radioButton2.Checked) { list = new List<DateTime>(); DateTime date = new DateTime(); date = dt.AddHours(-24); for (int i = 0; i < 48; i++) { date = date.AddMinutes(30); list.Add(date); } } } private string time_to_string(DateTime dt) { int hours = dt.Hour-8; int minute = dt.Minute; string time = ""; time += dt.Year.ToString(); time += dt.Month.ToString().PadLeft(2, ‘0‘); if (hours < 0) { int day = dt.Day - 1; time += day.ToString().PadLeft(2, ‘0‘); int our = 24 + hours; time += our; } else { time += dt.Day.ToString().PadLeft(2, ‘0‘); time += hours.ToString().PadLeft(2, ‘0‘); } if (minute < 30) { time += "00"; } else { time += "30"; } time += "00000"; return time; } private void MainForm_Load(object sender, EventArgs e) { this.skinEngine1.SkinFile = @"MacOS.ssk"; AddList(); //listboxliebiao.SelectedIndex =0; this.comboBox1.Items.Add("1"); this.comboBox1.Items.Add("3"); this.comboBox1.Items.Add("5"); comboBox1.SelectedIndex = 0; } private void radioButton2_Click(object sender, EventArgs e) { AddList(); //默认选中第一项 listboxliebiao.SelectedIndex = 0; } private void listboxliebiao_SelectedIndexChanged(object sender, EventArgs e) { DateTime dt =Convert.ToDateTime( this.listboxliebiao.SelectedItem); string name = time_to_string(dt); string url = "http://image.weather.gov.cn/product/" + dt.Year.ToString() + "/" + dt.Year.ToString() + dt.Month.ToString().PadLeft(2, ‘0‘) + "/" + dt.Year.ToString() + dt.Month.ToString().PadLeft(2, ‘0‘) + dt.Day.ToString().PadLeft(2, ‘0‘) + "/WXCL/medium/SEVP_NSMC_WXCL_ASC_E99_ACHN_LNO_PY_"; url = url + name + ".JPG"; pictureBoxyuntu.LoadAsync(url); } private void radioButton1_Click(object sender, EventArgs e) { AddList(); //默认选中第一项 listboxliebiao.SelectedIndex =0; } private void btnStart_Click(object sender, EventArgs e) { ////如果播放过程中点击247小时按钮则停止播放,防止报错 if (radioButton1.Checked == true) { radioButton2.Enabled = false; } else { radioButton1.Enabled = false; } if (listboxliebiao.SelectedIndices.Count < 1) return; try { double dInteral = Convert.ToDouble(comboBox1.Text); dInteral = dInteral * 1000; if (dInteral < 1000) { MessageBox.Show("输入的播放速度过小!","提示"); return; } SatelliteTimer.Interval = (int)dInteral; } catch (Exception ex) { MessageBox.Show("播放出错!","提示"); } SatelliteTimer.Enabled = true; } private void btnStop_Click(object sender, EventArgs e) { //如果停止,则12小时和24小时均可选择 { radioButton1.Enabled = true; radioButton2.Enabled = true; } SatelliteTimer.Enabled = false; SatelliteTimer.Interval = 1000; } private void SatelliteTimer_Tick(object sender, EventArgs e) { SatelliteTimer.Interval = Convert.ToInt32(comboBox1.Text) * 1000; int i = Convert.ToInt32(listboxliebiao.SelectedIndices[0]); if (i >= 0 && i < listboxliebiao.Items.Count - 1) { listboxliebiao.SetSelected(i+1,true); } } private void timerSystemtimenow_Tick(object sender, EventArgs e) { labeltimenow.Text = "当前系统时间:"+System.DateTime.Now.ToString(); labeltimenow.ForeColor = Color.Blue; } } }更改优化后效果图:
新版本更新内容:
1.增加系统时间显示;
2.默认选中listbox和combobox第一个选项;
3.增加Mac皮肤显示;
4.调整页面布局;
5.更改播放过程中选择另一个radioButton出错的Bug。