using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Media; //多媒體記數(shù) using System.Runtime.InteropServices; namespace V8.__Timer控件 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { label2.Text = DateTime.Now.ToString(); } private void timer1_Tick(object sender, EventArgs e) { // 需要將 timer1 Enable 設置為True // MessageBox.Show("我會不停的彈出","嘗嘗我的厲害"); label1.Text = label1.Text.Substring(1) + label1.Text.Substring(0,1); } private void timer2_Tick(object sender, EventArgs e) { SoundPlayer sp = new SoundPlayer(); sp.SoundLocation = @"C:\Documents and Settings\All Users\Documents\My Music\示例音樂\New Stories (Highway Blues).wma"; if (DateTime.Now.Hour == 18 && DateTime.Now.Minute == 46 && DateTime.Now.Millisecond == 0) { sp.Play(); //單詞播放 //sp.PlayLooping(); //循環(huán)播放 } if (DateTime.Now.Hour == 17 && DateTime.Now.Minute == 9&& DateTime.Now.Millisecond == 0) { sp.Stop(); //停止播放 } label2.Text = DateTime.Now.ToString(); } } } using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace V8._ { public partial class Form1 : Form { public int t=0; public Form1() { InitializeComponent(); } private void timer1_Tick(object sender, EventArgs e) { t++; label1.Text = GetTimeFormat(t); } public string GetTimeFormat(int t) { string hh, mm, ss, mms; int temp = t / 100; //獲取已秒為單位總秒數(shù) int ms = t % 100; int h = temp / 3600; int m = temp / 60 % 60; int s = temp % 60; if (ms < 10) mms = "0" + ms.ToString(); else mms = ms.ToString(); if (h < 10) hh = "0" + h.ToString(); else hh = h.ToString(); if (m < 10) mm = "0" + m.ToString(); else mm = m.ToString(); if (s < 10) ss = "0" + s.ToString(); else ss = s.ToString(); return hh + ":" + mm + ":" + ss + "." + ms; } private void Form1_Load(object sender, EventArgs e) { } private void startbtn_Click(object sender, EventArgs e) { if (timer1.Enabled) { timer1.Stop(); startbtn.Text = "開始計時"; clearbtn.Enabled = true; } else { t = 0; timer1.Start(); startbtn.Text = "停止計時"; clearbtn.Enabled = false; } } private void clearbtn_Click(object sender, EventArgs e) { label1.Text = GetTimeFormat (0); } } } |
|
來自: 時間劇毒 > 《第十二章:Windows窗體技術及基礎控件》