您当前的位置:首页 > 计算机 > 编程开发 > .net

C#编程:用Thread获取系统时间

时间:05-25来源:作者:点击数:
CDSY,CDSY.XYZ

C#编程:用Thread获取系统时间

private void button1_Click(object sender, EventArgs e)
        {
            System.Threading.Thread p_thread =
                new System.Threading.Thread(
                    () =>
                    {
                        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();
        }

 

CDSY,CDSY.XYZ
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门