一:午夜倒计时(Minutes2Midnight)WM程序开发入门例程系列

主要源代码:
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace Minutes2Midnight
  10. {
  11.     public partial class frmM2M : Form
  12.     {
  13.         public frmM2M()
  14.         {
  15.             InitializeComponent();
  16.         }
  17.         private void timer_Tick(object sender, EventArgs e)
  18.         {
  19.             //获取离午夜12:00的时间间隔(时间戳)
  20.             TimeSpan timeSpan = DateTime.Now.Date.AddDays(1) - DateTime.Now;
  21.             //格式化输出
  22.             labelHours.Text = string.Format("{0} of 24 hours left", timeSpan.Hours);//小时
  23.             labelMinutes.Text = string.Format("{0} of 60 minutes left", timeSpan.Minutes);//分钟
  24.             labelSeconds.Text = string.Format("{0} of 60 seconds left", timeSpan.Seconds);//秒
  25.             /*
  26.             //Custom Numeric Format Strings自定义数值格式字符串 详情参阅MSDN 以下是VS2008本地连接帮助,以后不再声明
  27.             ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/dv_fxfund/html/6f74fd32-6c6b-48ed-8241-3c2b86dea5f4.htm 
  28.             */
  29.             labelTotalMinutes.Text = string.Format("{0} of 1440 total minutes left", timeSpan.TotalMinutes.ToString("#.0"));//总分钟
  30.             labelTotalSeconds.Text = string.Format("{0} of 86400 total seconds left", timeSpan.TotalSeconds);//总秒数
  31.             //设置进度条的值
  32.             progressBarTotal.Value = 86400 - (int) timeSpan.TotalSeconds;//86400=3600*24
  33.             progressBarHours.Value = 24 - timeSpan.Hours;
  34.             progressBarMinutes.Value = 60 - timeSpan.Minutes;
  35.             progressBarSeconds.Value = 60 - timeSpan.Seconds;
  36.             progressBarTotalMinutes.Value = 1440 - (int) timeSpan.TotalMinutes;//1440=60*24
  37.             progressBarTotalSeconds.Value = 86400 - (int) timeSpan.TotalSeconds;
  38.         }
  39.         private void menuItemAbout_Click(object sender, EventArgs e)
  40.         {
  41.             //实例化 关于 窗口 并显示
  42.             frmAbout aboutForm = new frmAbout();
  43.             aboutForm.ShowDialog();
  44.         }
  45.         private void menuItemExit_Click(object sender, EventArgs e)
  46.         {
  47.             //关闭窗口
  48.             this.Close();
  49.         }
  50.     }
  51. }

 

知识要点概括:

1Minutes 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();

 

StringFormat用法

参加源代码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值