您的位置:首页 > 其它

丶动态获取系统当前时间

2011-10-23 18:49 232 查看
效果图:



代码:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace Example53

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

System.Threading.Thread P_thread =

new System.Threading.Thread(

() => //使用Lambda 表达式

{

while (true)

{

this.Invoke(

(MethodInvoker)delegate() //操作窗体线程

{

this.Refresh(); //窗体刷新

Graphics P_graphics = CreateGraphics(); //创建一个绘图对象

P_graphics.DrawString("当前系统时间:" + //绘制系统时间

DateTime.Now.ToString(

"yyyy 年 MM 月 dd 日 HH 时 mm 分 ss 秒"),

new Font("宋体", 15),

Brushes.Blue, new Point(10, 10));

}

);

System.Threading.Thread.Sleep(1000); //睡眠一秒钟

}

}

);

P_thread.IsBackground = true; //将线程设置为后台线程

P_thread.Start();

}

private void Form1_Click(object sender, EventArgs e)

{

this.Close();

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: