效果图:

代码:

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

        }

    }

}

posted on 2011-10-23 18:49  C#_初学者  阅读(408)  评论(0编辑  收藏  举报