C# 視窗程式範例 -- 數位時鐘

基礎篇

C# 簡介

開發環境

變數與運算

流程控制

陣列

函數

物件

例外處理

函式庫篇

檔案處理

資料結構

正規表達式

Thread

應用篇

視窗程式

媒體影音

網路程式

遊戲程式

手機程式

資料庫

雲端運算

特殊功能

委派

擴展方法

序列化

LinQ

WPF

網路資源

教學影片

投影片

教學文章

軟體下載

考題解答

101習題

專案下載:Clock.zip

介面設計

請從工具箱中拉出一個 label 與一個 Timer,如下圖所示。

程式內容

然後將 Form1.cs 的程式改成如下內容。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TimerDemo
{
 public partial class Form1 : Form
 {
 public Form1()
 {
 InitializeComponent();
 timer1_Tick(this, null);
 timer1.Interval = 1000; // 設定每秒觸發一次
 timer1.Enabled = true; // 啟動 Timer
 }
 private void timer1_Tick(object sender, EventArgs e)
 {
 DateTime time = DateTime.Now;
// label1.Text = time.TimeOfDay.ToString();
// label1.Text = time.Hour + ":" + time.Minute + ":" + time.Second;
 label1.Text = String.Format("{0:00}:{1:00}:{2:00}", 
 time.Hour, time.Minute, time.Second);
 }
 }
}

執行結果

這樣就設計好一個數位時鐘了。

ClockRun.png

Post preview:

(will not be published)


本網頁的作者、授權與引用方式

作者
陳鍾誠,於金門大學資訊工程系,電子郵件:wt.ude.uqn|ccc#wt.ude.uqn|ccc,網站:http://ccckmit.wikidot.com
授權
本文採用創作共用 (Creative Common) 3.0 版的 姓名標示─非商業性─相同方式分享 授權條款,歡迎轉載或修改使用,但若做為商業使用時必須取得授權,引用本文時請參考下列格式。
中文版 (APA格式)
陳鍾誠 (28 Sep 2010 01:39),(網頁標題) C# 視窗程式範例 — 數位時鐘,(網站標題) 免費電子書:C# 程式設計,28 Sep 2010 01:39,取自 http://cs0.wikidot.com/clock ,網頁修改第 5 版。
英文版 (APA格式)
Chung-Chen Chen (28 Sep 2010 01:39), Retrieved 28 Sep 2010 01:39 from http://cs0.wikidot.com/clock, Page Revision 5.
page revision: 5, last edited: 28 Sep 2010 02:40
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License
Click here to edit contents of this page.
Click here to toggle editing of individual sections of the page (if possible). Watch headings for an "edit" link when available.
Append content without editing the whole page source.
Check out how this page has evolved in the past.
If you want to discuss contents of this page - this is the easiest way to do it.
View and manage file attachments for this page.
A few useful tools to manage this Site.
Change the name (also URL address, possibly the category) of the page.
View wiki source for this page without editing.
View/set parent page (used for creating breadcrumbs and structured layout).
Notify administrators if there is objectionable content in this page.
Something does not work as expected? Find out what you can do.
General Wikidot.com documentation and help section.
Wikidot.com Terms of Service - what you can, what you should not etc.
Wikidot.com Privacy Policy.

AltStyle によって変換されたページ (->オリジナル) /