丶动态获取系统当前时间
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();
}
}
}
代码:
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();
}
}
}
相关文章推荐
- 动态获取系统当前时间
- js动态获取当前系统时间+js字符串转换为date日期对象
- c# 动态获取系统当前日期和时间
- 动态获取系统当前时间
- java获取获得Timestamp类型的当前系统时间
- C# 获取24小时制的当前系统时间
- 获取系统当前时间时带有星期的处理方法
- .net获取系统当前时间
- js获取当前系统时间
- android 获取当前系统时间
- 获取当前系统时间
- Javascript中获取系统的当前时间
- C++获取当前系统时间的方法(转载)
- Java获取系统当前时间不正确
- 【日期时间】批处理标准化获取当前系统日期
- .net获取系统当前时间
- 如何用C语言获取当前系统时间?
- cocos2dx 3.x(获取当前系统时间)
- 动态显示当前系统时间和移除定时器
- shell获取当前系统时间