- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace Minutes2Midnight
- {
- public partial class frmM2M : Form
- {
- public frmM2M()
- {
- InitializeComponent();
- }
- private void timer_Tick(object sender, EventArgs e)
- {
- //获取离午夜12:00的时间间隔(时间戳)
- TimeSpan timeSpan = DateTime.Now.Date.AddDays(1) - DateTime.Now;
- //格式化输出
- labelHours.Text = string.Format("{0} of 24 hours left", timeSpan.Hours);//小时
- labelMinutes.Text = string.Format("{0} of 60 minutes left", timeSpan.Minutes);//分钟
- labelSeconds.Text = string.Format("{0} of 60 seconds left", timeSpan.Seconds);//秒
- /*
- //Custom Numeric Format Strings自定义数值格式字符串 详情参阅MSDN 以下是VS2008本地连接帮助,以后不再声明
- ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/dv_fxfund/html/6f74fd32-6c6b-48ed-8241-3c2b86dea5f4.htm
- */
- labelTotalMinutes.Text = string.Format("{0} of 1440 total minutes left", timeSpan.TotalMinutes.ToString("#.0"));//总分钟
- labelTotalSeconds.Text = string.Format("{0} of 86400 total seconds left", timeSpan.TotalSeconds);//总秒数
- //设置进度条的值
- progressBarTotal.Value = 86400 - (int) timeSpan.TotalSeconds;//86400=3600*24
- progressBarHours.Value = 24 - timeSpan.Hours;
- progressBarMinutes.Value = 60 - timeSpan.Minutes;
- progressBarSeconds.Value = 60 - timeSpan.Seconds;
- progressBarTotalMinutes.Value = 1440 - (int) timeSpan.TotalMinutes;//1440=60*24
- progressBarTotalSeconds.Value = 86400 - (int) timeSpan.TotalSeconds;
- }
- private void menuItemAbout_Click(object sender, EventArgs e)
- {
- //实例化 关于 窗口 并显示
- frmAbout aboutForm = new frmAbout();
- aboutForm.ShowDialog();
- }
- private void menuItemExit_Click(object sender, EventArgs e)
- {
- //关闭窗口
- this.Close();
- }
- }
- }
知识要点概括:
1:Minutes to Midnight Countdown (午夜倒计时) 2008-7-30
TimeSpan的用法① String.Format的用法 StringBuilder的用法
ProgressBar控件 WebBrowser控件② Timer控件 MainMenu控件
①
利用TimerSpan计算 天数倒计时
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DateTime dt1 = new DateTime(2008, 8, 8);
DateTime dt2 = DateTime.Now;
TimeSpan timespan;
private void button1_Click(object sender, EventArgs e)
{
timespan = dt1 - dt2;
MessageBox.Show(Math.Ceiling (timespan.TotalDays).ToString ());
}
}
②
WebBrowser控件用法
webBrowser.DocumentText
Gets or sets the HTML contents of the page displayed in the System.Windows.Forms.WebBrowser control.
StringBuilder sb = new StringBuilder();
//在实例末尾添加指定的字符串
sb.Append(@"<b>Minutes to Midnight Countdown</b>").Append(@"<br/>").Append(@"<br/>");
sb.Append(@"Day 01 application of 30 Days of .NET [Windows Mobile Applications]").Append(@"<br/>");
sb.Append(@"http://www.cjcraft.com/blog/").Append(@"<br/>");
sb.Append(@"<br/>").Append(@"<br/>");
sb.Append(@"<b>Does your company need help with your next, or first, Windows Mobile project.</b> ").Append(@"<br/>").Append(@"<br/>");
sb.Append(@"I'm available for consulting and contracting. ");
sb.Append(@"Feel free to contact me about Windows Mobile device application development. ").Append(@"<br/>").Append(@"<br/>");
sb.Append(@"<a href=""cjcraft@mail.com"">cjcraft@mail.com</a>");
webBrowser.DocumentText = sb.ToString();
③ String。Format用法
参加源代码