实现效果:

动态获取当前日期和时间

关键知识:

动态获取当前日期和时间

实现代码:

        private void Form1_Load(object sender, EventArgs e)
        {
            System.Threading.Thread thread = //创建线程
                new System.Threading.Thread(
                () =>   //使用lambda表达式
                {
                    while (true) //无限循环
                    {
                        this.Invoke(    //操作窗体线程
                            (MethodInvoker)delegate() //使用匿名方法
                            {
                               this.Refresh();  //刷新窗体
                                Graphics g =    //创捷绘图对象
                                    CreateGraphics();
                                g.DrawString("系统时间:\n"+ //在窗体中绘出系统时间
                                    DateTime.Now.ToString(
                                    "yyy年MM月dd日hh时mm分ss秒"),
                                    new Font("宋体",15),
                                    Brushes.Blue,
                                    new Point(10,10));
                            });
                        System.Threading.Thread.Sleep(1000);//线程挂起1秒
                    }
                });
            thread.IsBackground = true;//将线程设置为后台线程
            thread.Start();//启动线程
        }

  

相关文章:

  • 2021-11-29
  • 2021-11-29
  • 2021-12-22
  • 2021-12-23
  • 2021-10-07
  • 2022-02-16
  • 2021-10-13
猜你喜欢
  • 2021-11-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2021-11-28
相关资源
相似解决方案